问题描述
我想将NSUInteger保存为我的核心数据,我不知道应该使用哪种类型(整数16,32,64)来满足所需的空间。
从我的理解
整数16可以有最小值-32,768到32,767
整数32可以有最小值-2,147,483,648到2,147,483,647
整数64可以有最小值 - 非常大到非常大
,NSUInteger是unsiged long的类型def,等于unsigned int( objective-c中的类型在iPhone上)
所以如果我将NSUInteger转换为NSNumber与numberWithUnsignedInteger:并保存为NSNumber(整数32)我可以安全地检索我的数据 是否需要 NSUInteger 的整个范围 / code>?在iOS上是一个无符号的32位值,这可能会非常大。它会找到一个有符号的64位。
但你可能不需要那么多的精度。 uint32_t
的最大值为 UINT32_MAX
,为4,294,967,295(40亿)。如果您每秒增加一次,则需要超过136年才能达到该值。您的用户的iPhone不会在那时...:)
I want to keep NSUInteger into my core data and I don't know which type should I use (integer 16, 32, 64) to suit the space needed.
From my understanding
Integer 16 can have minimum value of -32,768 to 32,767
Integer 32 can have minimum value of -2,147,483,648 to 2,147,483,647
Integer 64 can have minimum value of -very large to very large
and NSUInteger is type def of unsiged long which equal to unsigned int (Types in objective-c on iPhone)
so If I convert my NSUInteger to NSNumber with numberWithUnsignedInteger: and save it as NSNumber(Integer 32) I could retrieve my data back safely right ?
Do you really need the entire range of an NSUInteger
? On iOS that's an unsigned 32 bit value, which can get very large. It will find into a signed 64 bit.
But you probably don't need that much precision anyway. The maximum for a uint32_t
is UINT32_MAX
which is 4,294,967,295 (4 billion). If you increment once a second, it'll take you more than 136 years to reach that value. Your user's iPhone won't be around by then... :)
这篇关于核心数据中的NSNumber(整数16,32,64)应该用于保持NSUInteger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!