sosale151
sosale151

Reputation: 380

Core Data changes value of 64-bit Integer

I'm new to iOS development and have been using core data in the app I'm developing. I have a timestamp value which is stored as a property in my NSManagedObject and this property is declared as an Integer-64 bit in the core data model. It's declared as an NSNumber in the NSManagedObject subclass.

When I run this on my iPhone 6 and iOS 8, the code works fine and the timestamp gets stored as it's supposed to. However, when I run the same code on my iPhone 4 which has iOS 7 on it, the number is changed. I'm unsure why this happens as the core data model is the same and declares the property as an Integer-64.

When I create this NSManaged object and populate the timestamp property, I use

[NSNumber numberWithUnsignedInteger: timeStampValue]

I then save the context. But when I fetch the object and read the value, the value changes on my iPhone 4/iOS7. I'm unsure if this is an iPhone 4 or an iOS7 issue as I do not possess another device to test this on. It also works fine on the emulator.

If anyone could tell me why this is happening and what I could do to fix it, I'd greatly appreciate it.

If any more information is needed, i'll provide it.

Upvotes: 0

Views: 315

Answers (1)

sosale151
sosale151

Reputation: 380

To anyone who might have this problem in the future. I have found the solution. It was an issue with the iPhone 4.

The problem was not with Core Data or the 64 bit integer setting there. The error arrived due to objective-c's size of long. This is how I retrieved the initial timestamp value from the server and I had stored it as a long. I'd assumed the long to be 64 bits (like in Java).

On the iPhone 6, a long was indeed 64 bits and the value hence did not change. On the iPhone 4 however, the size of a long was 32 bits and the value was corrupted for the large number. Changing the storing variable to a long long solved this problem.

Upvotes: 0

Related Questions