CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jun 2016 |
Maintained by Sean G. Young.
Key value coding is a bit of Cocoa magic that remains unique to ObjC through NSObject
. However, NSObject's KVO methods throw exceptions when things go south and these cannot be caught in Swift. The category this library provides wraps NSObject's KVO methods in @try/@catch blocks and when an exception is thrown an NSError
object is populated instead.
Usage is simple. First import:
import SGYKVCSafeNSObject
Then use key value coding as before by optionally passing NSError
:
let object = NSObject()
var error: NSError?
object.setValue("any value", forKey: "not a key", error:&error)
if let error = error { NSLog("Key value assignment error: \(error.localizedDescription).") }
NSException
in these methods seems to randomly cause an EXC_BAD_ACCESS. So to maintain safety the exception object is not packed into a userInfo dictionary until I can nail down the reason.