Setting a Core Data Entity Value
Setting a Core Data Entity Value
- Subject: Setting a Core Data Entity Value
- From: Ian was here <email@hidden>
- Date: Fri, 04 Dec 2015 21:42:46 +0000 (UTC)
I have a core data model with an entity called "Entries". One of the fields in this entity is called "date". I have a table where all columns are bound to an array controller. The array controller is bound to an object model context. I have an "Add" button that adds a row to the table. When the "Add" button is pressed, I would like to set the date column to today's date. I setup a notification that calls managedObjectContextDidChange: whenever a new row is added. It seems this would be the logical place to set the date. However, this throws an exception. I'm sure there's a way to do this, I'm just not seeing how.
- (void)managedObjectContextDidChange:(NSNotification *)notification{ NSDictionary *userInfo = [notification userInfo]; NSArray *objects = [[userInfo objectForKey:NSInsertedObjectsKey] allObjects]; NSManagedObject *managedObject = [objects lastObject]; NSEntityDescription *entityDescription = [managedObject entity]; [entityDescription setValue:[NSDate date] forKey:@"date"];}
Thanks!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden