0

I am using the following code to assign a unix timestamp to an Integer 32 field called updated. This translates into the auto-generated NSManagedObject subclasses as NSNumber. Here's what I'm doing to set a value.

NSNumber *timestamp = [NSNumber numberWithInt:(int) [[NSDate date] timeIntervalSince1970]];
self.deal.updated = timestamp;

However, when I do this, the value that gets saved to updated is just '1', i.e. the single digit 1.

I have also tried this:

NSNumber *timestamp = [NSNumber numberWithDouble:[[NSDate date] timeIntervalSince1970]];
self.deal.updated = timestamp;

I don't see this as such a complicated task and don't see what I'm missing.

M Azam
  • 518
  • 1
  • 7
  • 28
  • [this](http://stackoverflow.com/questions/2494542/how-does-the-iphone-sdk-core-data-system-store-date-types-to-sqlite) may help you – Bilal Saifudeen Jan 09 '14 at 05:56
  • 2
    possible duplicate of [Cannot use a predicate that compares dates in Magical Record](http://stackoverflow.com/questions/16591982/cannot-use-a-predicate-that-compares-dates-in-magical-record) - (You should not call a Core Data attribute "updated" or "deleted".) – Martin R Jan 09 '14 at 06:57
  • 1
    Martin R is right. You have chosen to name your property the same as an existing method on NSManagedObject, - (BOOL)isUpdated. Thus every time you write to your store the value comes back as 1. – ImHuntingWabbits Jan 09 '14 at 17:21
  • Thanks @MartinR and @ImHuntingWabbits. Changing it from updated to changed worked. I figured it was being set to a similar property but overlooked the `isUpdated` method on `NSManagedObject` – M Azam Jan 10 '14 at 18:23

0 Answers0