这是文件说的内容.这是接口文件中的声明.
@interface XYZPerson : NSObject
@property NSString *firstName;
@property NSString *lastName;
@end
Run Code Online (Sandbox Code Playgroud)
接下来它说:使用访问器方法来获取或设置属性值
您可以通过访问器方法访问或设置对象的属性:
NSString *firstName = [somePerson firstName];
[somePerson setFirstName:@"Johnny"];
Run Code Online (Sandbox Code Playgroud)
我不明白"somePerson"指的是什么.它从哪里来的?
在此示例中,somePerson可能是XYZPerson该类的一个实例.代码作者只是假设你会意识到这一点.
// create a person
XYZPerson *somePerson = [[XYZPerson alloc] init];
// set that person's "firstName" property to "Johnny"
[somePerson setFirstName: @"Johnny"]
// Get the firstName property of the somePerson object
NSString *personsName = [somePerson firstName];
// personsName should be the string "Johnny"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
36 次 |
| 最近记录: |