Last active
April 15, 2018 21:33
-
-
Save own2pwn/385367816219f53e1991f18aded55b09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class RealmService { | |
public var realm: Realm { | |
return try! Realm() | |
} | |
// MARK: - Interface | |
public func nextID<Model: Object>(for modelType: Model.Type) -> Int { | |
let className = String(describing: modelType) | |
// | |
// Stuck here, can't get realm instance. | |
// | |
guard let schema = realm.objects(RealmSchema.self).filter("className = %@", className).first else { | |
let newModel = RealmSchema(with: className) | |
save(newModel) | |
return 0 | |
} | |
let currentID = schema.nextID | |
updateAsync(schema, { $0.incrementID() }) | |
return currentID | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment