creating integer array
hi i am new iphone programmer i want to know that can we create array of integer,array of strings....etc seperatly like c++ if yes then how.... i have read about the example g开发者_如何学JAVAiven on this site but that is c style of array.... please reply
NSArray
is the standard array class in Cocoa/Cocoa Touch. It can contain objects, but not primitives.
You can store integers in an array by wrapping them with an NSNumber
object like so:
NSNumber *myInt = [NSNumber numberWithInt:1];
Then you can store it in an array like so:
NSArray *myArray = [NSArray arrayWithObject:myInt];
NSArray *arr = [NSArray arrayWithObjects:@"a", @"b", @"c", nil];
NSArray *arr = [NSArray arrayWithObjects:[NSNumber numberWithInteger:1]
, [NSNumber numberWithInteger:2]
, [NSNumber numberWithInteger:3]
, nil];
Here's a reference.
精彩评论