• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Setting a Core Data Entity Value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: ARC and IBOutlet - strong vs weak......
  • Next by Date: Swift screensavers in Ubuntu?
  • Previous by thread: Re: ARC and IBOutlet - strong vs weak......
  • Next by thread: Setting a Core Data Entity Value
  • Index(es):
    • Date
    • Thread