1、@property关键字的作用是:自动生成getter、setter方法的声明;
2、语法:
@property 数据类型 名称;
3、原理:编译器在编译时,会根据@property生成getter和setter方法的实现。
4、@synthesize关键字的作用是:自动生成gette、setter方法的实现;
5、语法:
@synthesize @property 名称;
6、做的事情:
a、生成1个真私有属性;
b、将参数直接赋值给自动生成的那个私有属性,并没有做任何逻辑验证。如果需要getter和setter有自己的逻辑验证,那么就自己重写;
c、将生成的私有属性返回。
7、@property增强
生成私有属性,并且生成getter和setter的声明和实现。
本文详细介绍了Objective-C中@property和@synthesize关键字的作用与用法。@property用于声明自动生成getter和setter方法,而@synthesize则用于生成这些方法的具体实现。此外,还讲解了@synthesize如何创建私有属性及其实现细节。
304

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



