比如说有这样一段代码:
在.h中给了一个类的这个属性
@interface groupmodel : NSObject@property (nonatomic,copy)NSArray* friends;然后在.m中写了一个set的方法:
-(void)setFriends:(NSArray *)friends
{
NSMutableArray* data = [NSMutableArray array];
for(NSDictionary* dictdata in friends)
{
groupmodel* model = [[groupmodel alloc] init];
[model setValuesForKeysWithDictionary:dictdata];
[data addObject:model];
}
_friends = [data copy];
}请问这种情况的时候,nsarray* friends一开始并没有分配数据空间大小吗?还是什么机制呢?谢谢。
在.h中给了一个类的这个属性
@interface groupmodel : NSObject@property (nonatomic,copy)NSArray* friends;然后在.m中写了一个set的方法:
-(void)setFriends:(NSArray *)friends
{
NSMutableArray* data = [NSMutableArray array];
for(NSDictionary* dictdata in friends)
{
groupmodel* model = [[groupmodel alloc] init];
[model setValuesForKeysWithDictionary:dictdata];
[data addObject:model];
}
_friends = [data copy];
}请问这种情况的时候,nsarray* friends一开始并没有分配数据空间大小吗?还是什么机制呢?谢谢。
解决方案 »
- IOS 日期处理?????
- Objective-C引用C++类
- 关于web app的滑动效果
- 求指教,UIPageControl
- ios微信打不开连接怎么办
- 解决 iOS 7 UIBarButtonItem 在 navigationBar 中移位问题
- 圆角UIButton 背景使用图片之后 图片溢出
- IOS7 tableView被navigationBar挡住了
- ios用json格式传数据post路径和URL应该如何写?
- 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。
- 谁有HBuilder使用TCP的成功例子?
- 大家好,谁能推荐一下IOS的视频压缩框架,非常感谢!
并默认生成get和set方法(外部都是通过这两个方法访问的).你的属性名字叫friends,所以有个内部变量叫_friends
你重写了-(void)setFriends:(NSArray *)friends方法时,在方法内创建了一个数组
NSMutableArray* data = [NSMutableArray array];
这里已经分配了空间了
在最后你把这个属性_friends指向了这个数组data
_friends = [data copy];
所以你的friends就是你方法里的data,这样就知道空间哪里来的吧