using NSInteger in a loop
Do a NSInteger occupies memory? Should we use it i开发者_C百科n a FOR loop?
Look at the Apple documentation, a NSInteger is this :
#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
#else
typedef int NSInteger;
#endif
It's just 4 bytes on an iPhone, just like an int, you don't have to worry about memory.
NSInteger is just an alias for the native integer type. Cmd+Dbl Click on it and see.
1) It uses stack memory (I assume) while it is in scope and releases it when it goes out of scope.
2) Yes, use it in a for loop.
Also, see In Cocoa do you prefer NSInteger or int, and why?
精彩评论