CoreDataKit icon indicating copy to clipboard operation
CoreDataKit copied to clipboard

Support willSave on newly inserted objects

Open mac-cain13 opened this issue 11 years ago • 0 comments

CoreData doesn't call willSave for newly inserted objects. So many of my projects include this "fix", maybe CoreDataKit could include this as a optional fix that you can enable?!

// Apply "fix" so willSave is also called for inserted objects
NSNotificationCenter.defaultCenter().addObserverForName(NSManagedObjectContextWillSaveNotification, object: nil, queue: NSOperationQueue.mainQueue()) { notification in
      if let managedObjectContext = notification.object as? NSManagedObjectContext {
        for managedObject in managedObjectContext.insertedObjects {
          managedObject.willSave()
        }
      }
    }

mac-cain13 avatar Dec 05 '14 13:12 mac-cain13