我在我的 UIView 中声明了一个属性,如下所示:
@property (nonatomic, strong) NSMutableArray *finishedLines;
我初始化使用:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
//[self setFinishedLines:[[NSMutableArray alloc] init]];
[self setBackgroundColor:[UIColor grayColor]];
如果我取消注释 [self setFinishedLines..]
会有什么区别?
我声明属性的时候不是已经初始化了吗?
如果我取消注释但我不明白其中的逻辑,我会得到不同的结果。
最佳答案
objective-c 中的属性不会自动初始化。
您必须在构造函数中分配和初始化它(或使用 new,它基本上是 alloc 和 init 的快捷方式)。
self.finishedLines = [[NSMutableArray alloc] init]];
关于ios - UIView 的 initWithFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33629770/