Support default CRUD functions.
To run the example project, clone the repo, and run pod install from the Example directory first.
Open Example/RealmSwiftService.xcworkspace and run Example to see a simple demonstration.
all() -> Results<ObjectType>
find(by key: Any) -> ObjectType?
first() -> ObjectType?
last() -> ObjectType?
deleteAll() throws -> Bool
delete(list: List<ObjectType>) throws -> Bool
save(update: Bool) throws -> Bool
delete() throws -> BoolSupport 2 way implementation.
@objcMembers
class Cat: Object, RealmAccessible {
    dynamic var id = UUID().uuidString
    dynamic var name = ""
    override static func primaryKey() -> String? { return "id" }
    convenience init(name: String) {
        self.init()
        self.name = name
    }
}
// Save Realm Object
let cat = Cat(name: "tama")
try! cat.save()
// Get Realm Objects
Cat.all().forEach { print("\($0.name)-\($0.id)") } // tama-UUIDString
// RealmAccessible Example
// Instance Methods
let cat = Cat(name: "tama")  // Create Realm Object
try! cat.save()              // Save Object of Cat
try! cat.delete()            // Delete Object of Cat
// Static Methods
_ = Cat.all()                // Get All Object of Cat
_ = Cat.find(by: "id")       // Find Cat by id property
_ = Cat.first()              // Get First Object of Cat
_ = Cat.last()               // Get Last Object of Cat
try! Cat.deleteAll()         // Delete All Object of Cat
@objcMembers
class Dog: Object {
    dynamic var id = UUID().uuidString
    dynamic var name = ""
    override static func primaryKey() -> String? { return "id" }
    convenience init(name: String) {
        self.init()
        self.name = name
    }
}
// Save Realm Object
let dao = RealmDao<Dog>()
let dog = Dog(name: "pochi")
dao.save(dog)
// Get Realm Objects
dao.all().forEach { print("\($0.name)-\($0.id)") } // pochi-UUIDString
// Dao Example
let dao = RealmDao<Dog>()    // Create Dao of Dog
let dog = Dog(name: "pochi") // Create Realm Object
_ = dao.all()                // Get All Object of Dog
_ = dao.find(by: "id")       // Find Dog by id property
_ = dao.first()              // Get First Object of Dog
_ = dao.last()               // Get Last Object of Dog
try! dao.save(dog)           // Save Object of Dog
try! dao.delete(dog)         // Delete Object of Dog
try! dao.deleteAll()         // Delete All Object of Dog- iOS 10.0+
- Xcode 10.0+
- Swift 4.2+
Add RealmAccessible.swift, RealmDao.swift into your Project.
WIP...
RealmSwiftService is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'RealmSwiftService'and run pod install
Tsubasa Hayashi, yoku.rin.99@gmail.com
RealmSwiftService is available under the MIT license. See the LICENSE file for more info.