Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible core-data bug: attributes named 'updated' don't work correctly?

I have a Core Data entity called Post. One of it's attributes is called updated and it is a date. The stored XML looks like this:

<attribute name="updated" type="date">266164481.00000000000000000000</attribute>

From this I concluded that the data is being stored correctly. When I read the data back the returned value is a NSCFNumber, not an NSDate.

However, when I changed the name from updated to pubDate it worked properly. updated isn't declared in the headers for NSManagedObject or NSObject, so I guess it must be a private method.

Has anyone else experienced this? Should I report it to Apple?

I figured this out after a few hours of head scratching/foul mouth anger.

like image 396
Benedict Cohen Avatar asked Dec 29 '22 22:12

Benedict Cohen


2 Answers

NSManagedObject already has a property called isUpdated, which is set to YES when the object has changes that haven't been committed yet. This is a valid name for a getter for a BOOL value, so Core Data isn't doing anything with your updated property. You should rename your property.

like image 136
Alex Avatar answered May 07 '23 19:05

Alex


If you renaming your property is not an option, you may set the value expression to FUNCTION($source, "updated") in the mapping model. This will force the migration to use the method named "updated" instead of the updated property (e.g. [entity updated] instead of entity.updated).

In general though, I'd agree with the accepted answer if possible use a name other than "updated".

like image 25
Rob Brecher Avatar answered May 07 '23 18:05

Rob Brecher