【发布时间】:2012-08-11 18:23:39
【问题描述】:
设置:
ViewController 拥有来自PersonClass 的对象的MyArray。
PersonClass 只有两个属性:name 和 age。
问题:
当我想从MyArray 中的第一个对象中读取name 属性时,正确的方法是什么?
我必须像这样临时创建PersonClass 的实例吗?
PersonClass *tmp = [PersonClass alloc] init];
tmp = [MyArray objectAtIndex:0];
NSLog(@"%@", tmp.name);
或者我可以直接参考MyArray中objects的properties吗?
类似这样的:
NSLog(@"%@", [self.contactsArray objectAtIndex:0].name); // not working
【问题讨论】:
标签: iphone ios properties nsarray ivar