using NSInteger in a loop
-
05-12-2019 - |
Question
Do a NSInteger occupies memory? Should we use it in a FOR loop?
Solution
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.
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow