Duck
Duck

Reputation: 35953

iPhone - core data NSInteger, integer32, int or whatever

I have a core data value that is "integer 32". How should I set/get values from this?

with

[NSNumber numberWithInteger:X]

or with

[NSNUmber numberWithInt:X] 

?

Upvotes: 3

Views: 1620

Answers (2)

bryanmac
bryanmac

Reputation: 39296

As Jack said, it's a typedef. To add on to the answer, here's how you find out.

In XCode, hold down Apple key with your source file open. You'll see NSInteger become a link. After clicking on it, it will open it's definition.

#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 ||      NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif

Also, xlc0212's point is a good one. If you read the definition above, it's pretty clear.

Upvotes: 8

Jack Lawrence
Jack Lawrence

Reputation: 10772

NSInteger is simply a typedef for int, so you don't lose/gain integer precision one way or another. Both will work.

Upvotes: 6

Related Questions