Identifying which fields have changed before CoreData saves

前端 未结 1 1991
渐次进展
渐次进展 2021-02-13 12:06

//set up notifications

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(dataChanged:)
 name:NSManagedObjectContextDidSaveNotification
         


        
相关标签:
1条回答
  • 2021-02-13 12:48

    The following should do the trick, but you will need to use NSManagedObjectContextWillSaveNotification and access your updated objects through the same NSManagedObjectContext used to save the objects.

    for(NSManagedObject *obj in updatedObjects){
    
       NSDictionary *changes = [obj changedValues];
       // now process the changes as you need
    
    }
    

    See the discussion in the comments.

    0 讨论(0)
提交回复
热议问题