【发布时间】:2014-07-22 09:08:12
【问题描述】:
我使用的是 Xcode 5,问题出在以下两个 self.<something> 赋值语句 Xcode 中表示 expected expression,以及在 return 语句中。
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.questions = [NSArray arrayWithObjects: @"From what is cognac made?", @"What is 7+7?", @"What is the capital of Vermont?",nil];
self.answers = [NSArray arrayWithObjects: @"Grapes",@"14",@"Montpelier",nil];
}
return self;
}
【问题讨论】:
-
init 方法内部不要使用 self.questions ,始终使用烘焙变量 _question =
-
@Spynet 这不是真的。
-
-
-
@rckoenes 显然,您需要编写避免副作用的代码,一种方法是避免使用 setter 方法,但是即使使用实例变量,您仍然可以通过调用方法引起副作用当对象未完全初始化时在对象上。所以没有关于在
init中使用self的一揽子规则,只是你需要理解它。然而,这不是这个问题的目的。
标签: ios iphone objective-c ios7