English 中文(简体)
核心数据中有哪些NSNumber(16,32,64户)应该用于保持NSUInteger
原标题:What NSNumber (Integer 16, 32, 64) in Core Data should I use to keep NSUInteger

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 unsigned long which equal to unsigned int (Types in objective-c on iPhone)

...... 如果我把我的NSUInteger改为NSNumber,编号With UnsignInteger:并把它作为NSNumber(Integer 32) 我可以安全检索我的数据?

问题回答

really 是否需要整个<代码>NSUInteger? 在SOS,这一数值为32比值,可能非常大。 它将找到一份已签署的64条轨道。

但是,你可能不需要如此精确。 <代码>uint32_t ,即4 294 967 295 (40亿美元)。 如果你第二次加薪一次,就将超过136年的时间达到这一价值。 页: 1

If at all possible, when writing data to disk or across a network, it s best to be explicit about the size of value. Instead of using NSUInteger as the datatype, use uint16_t, uint32_t, or uint64_t depending on the range you need. This then naturally translates to Integer 16, 32, and 64 in Core Data.

理解为什么考虑这一设想:

  1. You opt to use Integer 64 type to store your value.
  2. On a 64-bit iOS device (eg iPhone 6) it stores the value 5,000,000,000.
  3. On a 32-bit iOS device this value is fetched from the store into an NSUInteger (using NSNumber s unsignedIntegerValue).

现在,由于NSUInteger在32个轨道装置上仅限32个轨道,因此该数字已不超过5 000 000 000 000 000 000 000 000美元,因为只有一定比例的限额才能达到50亿。 如果您在步骤3中转换了NUInteger,uint64_t。 这样,价值仍将是50亿美元。

如果你绝对必须使用NSUInteger,那么你就有理由对上文所述问题持怀疑态度,并为之提供防御。

在将未签字的数值储存到似乎已签署的核心数据类型方面,你可以安全储存这些数值并检索:

NSManagedObject *object = // create object
object.valueNumber = @(4000000000); // Store 4 billion in an Integer 32 Core Data type
[managedObjectContext save:NULL] // Save value to store

// Later on
NSManagedObject *object = // fetch object from store
uint32_t value = object.valueNumber.unsignedIntegerValue; // value will be 4 billion




相关问题
iPhone Core Data Recursive Relationships

I m having some trouble with a recursive relationship in core data. I ve got a managed object called a "SearchCategory", and that category can have "Categories" and it can also have a "Category." In ...

Plist Hierarchy and All Option

I have a string of data in a plist, which I ve got to display, hierarchically like this: Menu>Chapter>SubChapter>item>item details This might be super simple, in my initial menu, how would I have ...

Fetched Properties v Relationships (Core Data - iPhone)

I m a new iPhone developer (of about 4 months or so) who is starting to look at Core Data. In the "Beginning iPhone 3 Development" book by Dave Mark it mentions that the main difference between ...

Cocoa Core Data newbie how-tos

I am one of the great unwashed masses of .NET developers keen to try their hands at Mac OS X development. At the moment I am trying to figure out the various elements of Cocoa and getting a bit stuck ...

中间储存的核心数据

我想将核心数据作为输入数据库服务器更大数据集的切身。

Limit the returned resultset in CoreData

In CoreData, if I want to limit the returned resultset to 100, is it enough to just set the fetch limit to 100, or do I need to set the fetch batch size to 100 as well?

热门标签