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.
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.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With