开发者

Should I use NSNumber or an int in an iPhone/iPad class?

I'm creating an object that will have two integers (or NSNumbers) and an NSDate as ivars. This object will be in an NSMutableArray. To my knowledge, we cannot put primative integers in an NSMutableArray, but will my object work with ints? The reason I don't want to use NSNumbers is because these will have to be mutable, and I don't really want to create a new NSNumber everytime.

Also, will using ints c开发者_如何转开发reate problems with iphone architecture differences?


1) You can safely use ints as ivars because they are wrapped in another object. NSNumber is just a Cocoa class wrapper for the different numeric types.

2)To be safe, you could use NSUInteger, which is typedefed like this:

#if __LP64__ || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif

So you will get the correct type for the current architecture.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜