# In Cocoa do you favor NSInteger or int, and also why?

NSInteger/ NSUInteger are Cocoa - specified substitutes for the normal constructed - in types.

Exists any kind of advantage to making use of the NS * types over the constructed - ins? Which do you favor and also why? Are NSInteger and also int the very same size on 32 - little bit/ 64 - little bit systems?

0
2019-12-02 03:04:49
Source Share

The means I recognize it is that NSInteger et al. are style secure variations of the equivalent C types. Primarily their dimension differ relying on the style, yet NSInteger, as an example, is assured to hold any kind of legitimate reminder for the existing style.

Apple advises that you make use of these to collaborate with OS X 10.5 and also onwards, and also Apple is API :s will certainly utilize them, so it is most definitely an excellent suggestion to get involved in the behavior of utilizing them. They call for a little bit extra keying, yet in addition to that it does not appear to be any kind of factor not to utilize them.

0
2019-12-03 04:48:49
Source

I favor the typical c design affirmations yet just due to the fact that I switch over in between numerous languages and also I do not need to assume way too much concerning it yet seems like I need to start considering nsinteger

0
2019-12-03 04:44:34
Source

64 - little bit is in fact the raison d'être for NSInteger and also NSUInteger ; prior to 10.5, those did not exist. Both are merely specified as longs in 64 - little bit, and also as ints in 32 - little 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, utilizing them instead of the extra standard C types when you desire the 'little bit - indigenous' dimension.

0
2019-12-03 04:35:41
Source