'id' type object to NSArray problem
i have a NSDictionary and i get objects and keys in 'id' type format , with the following code:
NSDictionary *temp =[[NSDictionary alloc]initWithObjectsAndKeys:array1,@"array1",array2,@"array2",nil];
NSInteger count = [temp count];
id objects[count];
id ke开发者_Python百科ys[count];
[temp getObjects:objects andKeys:keys];
Where array1 and array2 are NSArrays. Is there a way to convert id objects[n] to a NSArray ? (kind of pointless in this example cause array1 and array2 are already there , but this would be helpful in many ways)
Yes. Your array objects
is C array, with count
items in it. NSArray
has an initializer that does what you need:
+ (id)arrayWithObjects:(const id *)objects count:(NSUInteger)count
So you would do
NSArray * myNewArray = [NSArray arrayWithObjects:objects count:count];
in this case.
Docs here.
精彩评论