Created
September 18, 2015 22:20
-
-
Save edwardIshaq/b5810ab35c30df10af24 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 Realm { | |
public class func saveClosure(dbClosure: (Realm)->()) { | |
do { | |
let rlm = try Realm() | |
rlm.write { () -> Void in | |
dbClosure(rlm) | |
} | |
} | |
catch let rlmError{ | |
print("Realm() generated error: \(rlmError)") | |
} | |
} | |
public class func saveClosure<T:Object>(dbClosure: Realm -> T) -> T { | |
let tPointer = UnsafeMutablePointer<T>.alloc(1) | |
do { | |
let rlm = try Realm() | |
rlm.write { | |
tPointer.memory = dbClosure(rlm) | |
} | |
} | |
catch let rlmError{ | |
print("Realm() generated error: \(rlmError)") | |
} | |
let result : T = tPointer.memory | |
tPointer.destroy() | |
tPointer.dealloc(1) | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment