我有一个 NSDictionary,我使用以下代码获取“id”类型格式的对象和键:
NSDictionary *temp =[[NSDictionary alloc]initWithObjectsAndKeys:array1,@"array1",array2,@"array2",nil];
NSInteger count = [temp count];
id objects[count];
id keys[count];
[temp getObjects:objects andKeys:keys];
其中 array1 和 array2 是 NSArray。 有没有办法将 id 对象[n] 转换为 NSArray ? (在这个例子中有点毫无意义,因为 array1 和 array2 已经存在,但这在很多方面都会有帮助)
最佳答案
是的。您的数组 objects
是 C 数组,其中包含 count
项。 NSArray
有一个初始化器可以满足您的需要:
+ (id)arrayWithObjects:(const id *)objects count:(NSUInteger)count
所以你会这样做
NSArray * myNewArray = [NSArray arrayWithObjects:objects count:count];
在这种情况下。
关于iphone - ‘id’类型对象转NSArray问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3643974/