2
votes

I am trying to store a long long value using Core Data. A value like 119143881477165. I am storing the value in NSNumber which is created using the convenience method numberWithUnsignedLongLong. The Core Data metadata has the type for this field is set to int64. The number gets stored properly, however when I retrieve this number using unsignedLongLongValue, the value is truncated.

Any suggestions?

1
Thank goodness you're using the unsingedLongLongValue.... The burnt variant isn't as pleasant.Dave DeLong

1 Answers

3
votes

You say it gets truncated... what type of primitive are you storing the value in? If you're using an NSUInteger, it's possible that the platform you're on has it defined as an unsigned int as opposed to an unsigned long.

If you explicitly want a long long, then use a long long.

The following works as expected:

unsigned long long number = 119143881477165;
NSNumber * numberValue = [NSNumber numberWithUnsignedLongLong:number];
unsigned long long extracted = [numberValue unsignedLongLongValue];

NSLog(@"original: %llu", number);
NSLog(@"extracted: %llu", extracted);

It logs:

2010-10-04 00:39:25.103 EmptyFoundation[790:a0f] original: 119143881477165

2010-10-04 00:39:25.106 EmptyFoundation[790:a0f] extracted: 119143881477165