功能:让编译好器自动编写一个与数据成员同名的方法声明来省去读写方法的声明
@property
@property int count;等效于在头文件中声明2个方法:- (int)count;
-(void)setCount:(int)newCount;@synthesize
实现文件(.m)中(xcode 4.5 以后可以省略)@synthesize count;等效于在实现文件(.m)中实现2个方法
- (int)count
{
return count;
}
-(void)setCount:(int)newCount
{
count = newCount;
}
本文详细介绍了Objective-C中使用@property和@synthesize关键字的作用。通过这两个关键字,开发者可以在不手动编写getter和setter方法的情况下,自动生成这些方法的声明与实现,从而简化了代码编写过程。
242

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



