My recommendation would be to use KVC. This may not be the most elegant solution, but a conceptually logical KVC application.
Watch for an attribute change. Register to change to init(entity:insertIntoManagedObjectContext:) or maybe better to awakeFromFetch and awakeFromInsert , and remove the observer in willTurnIntoFault .
init(entity: NSEntityDescription!, insertIntoManagedObjectContext context: NSManagedObjectContext!) { super.init(entity: entity, insertIntoManagedObjectContext: context) addObserver(self, forKeyPath: "attribute", options: NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Old, context: nil) } override func observeValueForKeyPath(keyPath: String!, ofObject object: AnyObject!, change: NSDictionary!, context: CMutableVoidPointer) { if (keyPath == "attribute") {
Updated for Swift 3:
init(entity: NSEntityDescription!, insertIntoManagedObjectContext context: NSManagedObjectContext!) { super.init(entity: entity, insertIntoManagedObjectContext: context) addObserver(self, forKeyPath: "attribute", options: [.old, .new], context: nil) } override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if keyPath == "attribute" {
Mundi
source share