The-Swift-2.0-Programming-Language-playground
The-Swift-2.0-Programming-Language-playground copied to clipboard
10-Properties:Stroed Properties and Instance Variables 存储属性和实例变量
Obj-C可以通过Property或者带有下划线“”前缀的实例变量对该变量进行赋值或读取,而Swift同一了这两种方式,只能通过点运算符对Property进行赋值或读取,而不能使用下划线“”前缀的实例变量进行这两项操作。
如: Obj-c:
@property (nonatomic, assign) BOOL isTrue;
self.isTrue = YES;
_isTrue = YES;
Swift:
var isTrue: Bool
self.isTrue = true
// _isTrue = true // Wrong!