功能:让编译好器自动编写一个与数据成员同名的方法声明来省去读写方法的声明。
如:
1、在头文件中:
- @property int count;
等效于在头文件中声明2个方法:
- - (int)count;
- -(void)setCount:(int)newCount;
2、实现文件(.m)中
- @synthesize count;
等效于在实现文件(.m)中实现2个方法。
- - (int)count
- {
- return count;
- }
- -(void)setCount:(int)newCount
- {
- count = newCount;
- }
本文详细介绍了Objective-C中使用属性(@property)声明数据成员的方法,及其如何自动生成相应的getter和setter方法。同时,通过@synthesize关键字实现了这些方法的具体代码。
1023

被折叠的 条评论
为什么被折叠?



