views:

73

answers:

1

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 create problems with iphone architecture differences?

+2  A: 

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.

Jergason
Thanks! I haven't had time to check because I think I've found a way to use NSIntegers, but I'll trust that you know what you're saying and will try integers later if NSIntegers don't work.