Skip to content

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

@joyingx

Description

@joyingx

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions