views:

29

answers:

1

Hi!

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

Any suggestions ?

A: 

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

Dave DeLong