The-Swift-2.0-Programming-Language-playground icon indicating copy to clipboard operation
The-Swift-2.0-Programming-Language-playground copied to clipboard

10-Properties:Stroed Properties and Instance Variables 存储属性和实例变量

Open joyingx opened this issue 9 years ago • 0 comments

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!

joyingx avatar Sep 16 '15 03:09 joyingx