2

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?

bradheintz
  • 2,942
  • 17
  • 24
user210504
  • 1,729
  • 2
  • 17
  • 36

1 Answers1

3

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

Community
  • 1
  • 1
Dave DeLong
  • 239,073
  • 58
  • 443
  • 495