In Cocoa do you prefer NSInteger or int, and why?

前端 未结 5 1700
臣服心动
臣服心动 2020-12-02 13:21

NSInteger/NSUInteger are Cocoa-defined replacements for the regular built-in types.

Is there any benefit to using the NS* types over the bu

5条回答
  •  攒了一身酷
    2020-12-02 13:53

    64-bit is actually the raison d'être for NSInteger and NSUInteger; before 10.5, those did not exist. The two are simply defined as longs in 64-bit, and as ints in 32-bit:

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

    Thus, using them in place of the more basic C types when you want the 'bit-native' size.

    CocoaDev has some more info.

提交回复
热议问题