pit*_*met 2 objective-c nsmutablearray
我有一个NSMutableArray,我加载了不同的对象(类).
现在我需要遍历数组并进入类以进行进一步操作.
我正在尝试这种方法......
for (id obj in allPointsArray)
{
///// this is where i need to bring the obj into a class to work with
NSInteger loc_x = obj.x_coord;
NSInteger loc_y = obj.y_coord;
}
Run Code Online (Sandbox Code Playgroud)
但我无法理解实际上将类从数组中移出并将其放入可用对象中.
x_coord和y_coord在存储在数组中的所有对象之间是通用的.
谢谢大家的帮助
如果数组中的对象是不同的类,您是否尝试做不同的事情?你可以这样做:
for (id obj in myArray) {
// Generic things that you do to objects of *any* class go here.
if ([obj isKindOfClass:[NSString class]]) {
// NSString-specific code.
} else if ([obj isKindOfClass:[NSNumber class]]) {
// NSNumber-specific code.
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7662 次 |
| 最近记录: |