【发布时间】:2013-08-21 08:37:08
【问题描述】:
我刚开始使用 ARC 进行编程,
当我用demo测试weak,strong@property时,发现了一个奇怪的东西;
这是代码:
在.h文件中,我创建了一个成员变量ctView并添加@property来管理getter和setter。
@interface ViewController : UIViewController
{
CTView * ctView;
}
@property(nonatomic,strong)CTView * ctView;
然后在.m文件中,viewdidload方法,我把点地址打印出来。
ctView = [[CTView alloc] initWithFrame:CGRectMake(10,10,300,400)];
NSLog(@"%p %p ",self.ctView,ctView);
日志:
0x0 0x7156530
谢谢大家,我弄错了,MRC 代码是在 LLVM GCC 4.2 编译器上,而 ARC 代码是 Apple LLVM 4.1,这个问题导致 MRC 应用程序崩溃,:)
【问题讨论】:
-
@Puneeet 问题是该属性返回一个
nil指针,而实例变量已被初始化。 -
坦率地说,我不明白反对意见。这是一个学习 Objective-C 的人提出的一个合理的问题,而且它也很清楚并且写得很好。
标签: ios properties automatic-ref-counting