Adding integer values ​​as array contents, iphone

I need to save some integer values ​​as the contents of an array. But when I try to do this, it gives a warning, Passing argument 1 of 'addObject' makes the pointer from the integer without translation. And, obviously, the value is not stored in the array. Here is the code.

NSUInteger i; for (i=0;i<5;i++){ [array addObject:i];} 
+4
source share
1 answer

NSArray -s cannot store id objects. You must insert it into NSNumber :

 NSUInteger i; for (i=0;i<5;i++) { [array addObject:[NSNumber numberWithUnsignedInteger:i]]; } 

either use CFArray with custom callbacks (but you sacrifice readability for performance) or use std::vector<NSUInteger> (but you need to use Objective-C ++).

+10
source

Source: https://habr.com/ru/post/1300148/


All Articles