使用CoreData在iPhone SDK中存储longLong值
我想使用Core Data存储长整型值。值为119143881477165.我将值存储在NSNumber中,它是使用方便的方法numberWithUnsignedLongLong创建的。 Core Data元数据将此字段的类型设置为int64。数字正确存储,但是当我使用unsignedLongLongValue检索此数字时,该值将被截断。
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.
有任何建议吗?
。什么类型的原语是你存储的值?如果你使用 NSUInteger
,可能你所使用的平台定义为 unsigned int
unsigned long
。
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
.
如果你明确想要一个 long long
,然后使用
long long
。
以下按预期工作:
unsigned long long number = 119143881477165;
NSNumber * numberValue = [NSNumber numberWithUnsignedLongLong:number];
unsigned long long extracted = [numberValue unsignedLongLongValue];
NSLog(@"original: %llu", number);
NSLog(@"extracted: %llu", extracted);
它日志:
2010-10-04 00:39:25.103 EmptyFoundation [790:a0f]原始:119143881477165
2010-10-04 00:39:25.103 EmptyFoundation[790:a0f] original: 119143881477165
2010-10-04 00:39:25.106 EmptyFoundation [ 790:a0f]提取:119143881477165
2010-10-04 00:39:25.106 EmptyFoundation[790:a0f] extracted: 119143881477165