Realm-JSONAPI icon indicating copy to clipboard operation
Realm-JSONAPI copied to clipboard

RealmSwift support

Open markst opened this issue 8 years ago • 1 comments

It would be great if there were support for Realm's swift objects. https://realm.io/docs/swift/latest/

markst avatar Mar 03 '17 06:03 markst

It seems that not a huge amount of work is required to support RealmSwift.

Since realm swift Object subclasses from RLMObjectBase rather than RLMObject. The two categoriesRLMObject+JSONAPIParser & RLMObject+JSONAPIResource can both be categories on RLMObjectBase rather.

Since RealmSwift Objects have no createOrUpdateInRealm... I've been able to create a swift function on my model such as:

open class func createOrUpdate(inRealm: RLMRealm!, withValue: [AnyHashable : Any]!) -> User! {
    let realm = try! Realm()
    let user: User = realm.create(User.self, value: withValue, update: true)
    return user
}

Which will succeed in creating a valid Realm object upon JSONAPIParserUtilities constructObjectWithJSON:inRealm

markst avatar Mar 03 '17 06:03 markst