Last active
July 6, 2017 21:15
-
-
Save ennioma/fab47a5ec2a651dbc2541e94e7ca66bf to your computer and use it in GitHub Desktop.
This file contains 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
extension RealmStorageContext { | |
func create<T: Storable>(_ model: T.Type, completion: @escaping ((T) -> Void)) throws { | |
guard let realm = self.realm else { | |
throw NSError() | |
} | |
try self.safeWrite { | |
let newObject = realm.create(model as! Object.Type, value: [], update: false) as! T | |
completion(newObject) | |
} | |
} | |
func save(object: Storable) throws { | |
guard let realm = self.realm else { | |
throw NSError() | |
} | |
try self.safeWrite { | |
realm.add(object as! Object) | |
} | |
} | |
func update(block: @escaping () -> Void) throws { | |
try self.safeWrite { | |
block() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment