Is there a problem to use int for class property?

advertisements

When I started with Cocoa, I remember that I read somewhere that int/float and similar should not be used for class properties and to use NS* equivalents (like NSInteger).

Is there a real hidden issue here why would that be better or it was just a voluntary coding rule by a person where I read that (and I can't for the life of me find where was that)?

So, what is better:

@interface xx...
    int myProp;
@end

or

@interface xx...
    NSInteger *myProp;
@end


The int version is fine, but NSInteger is preferred. NSInteger isn't an object and doesn't have to be referenced with a pointer — it's just a typedef that will allow the variable to be the native word size on both 32-bit and 64-bit computers. So the best option would be:

@interface SomeClass : NSObject {
    NSInteger aNumber;
@end

@implementation SomeClass
- (id)init {
    [super init];
    number = 42;
}
@end