property、synthesize、id
1、@property int age;
@synthesize age = _age;
//注意:必须在非ARC下,在“项目——》building setting——》all——》objcet-C Automic Reference Counting
//@property(nonatomic,retain) NSString *name相当于:
- (void)setName:(NSString *)name
{
if (_name != name)
{
[_name release];
_name = [name retain];
}
}
_name = [name retain];
// @property:可以自动生成某个成员变量的setter和getter声明
@property int age;
//- (void)setAge:(int)age;
//- (int)age;
@property int height;
//- (void)setHeight:(int)height;
//- (int)height;
@property(nonatomic,copy)NSString *name;
@property(nonatomic,retain)NSArray *group;
@synthesize age = _age;
{
//int _speed;
//int _wheels;
}
@property int speed;
@property int wheels;
//@property int speed, wheels;
- (void)test;
@end
@implementation Car
//@synthesize speed = _speed, wheels = _wheels;
// 注意:会访问_speed这个成员变量,如果不存在,就会自动生成@private类型的_speed变量
@synthesize speed = _speed;
@synthesize wheels = _wheels;
- (void)test
{
NSLog(@"速度=%d", _speed);
}
@end
@property int age;
property、synthesize、id的更多相关文章
- IOS 关键字self,super,copy, retain, assign , readonly , readwrite, nonatomic、 @synthesize、@property、@dynamic
IOS 关键字self,super,copy, retain, assign , readonly , readwrite, nonatomic. @synth ...
- iOS 内存管理-copy、 retain、 assign 、readonly 、 readwrite、nonatomic、@property、@synthesize、@dynamic、IB_DESIGNABLE 、 IBInspectable、IBOutletCollection
浅谈iOS内存管理机制 alloc,retain,copy,release,autorelease 1)使用@property配合@synthesize可以让编译器自动实现getter/setter方 ...
- Objective-C 点语法 成员变量的作用域 @property和@synthesize关键字 id类型
点语法 1.利用点语法替换set方法和get方法 方法调用 Student *stu = [Student new]; [stu setAge : 18]; int age = [stu age]; ...
- OC的特有语法-分类Category、 类的本质、description方法、SEL、NSLog输出增强、点语法、变量作用域、@property @synthesize关键字、Id、OC语言构造方法
一. 分类-Category 1. 基本用途:Category 分类是OC特有的语言,依赖于类. ➢ 如何在不改变原来类模型的前提下,给类扩充一些方法?有2种方式 ● 继承 ● 分类(Categor ...
- @property、@synthesize和dynamic的用法
原文: http://blog.csdn.net/hherima/article/details/8622948 @代表“Objective-C”的标志,证明您正在使用Objective-C语言 O ...
- ios中点语法、property跟synthesize用法
一:OC中得点语法 1> 点语法的基本使用: ·使用 对象.成员变量 可以实现设置成员变量值,和获取成员变量的值 2> 点语法的本质 (点语法是Xcode编译器自己帮我们完成的一个 ...
- OC语言@property @synthesize和id
OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字是编译器特性,让xcode可以自动生成getter和setter的声明 ...
- 李洪强iOS开发之OC语言@property @synthesize和id
OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字是编译器特性,让xcode可以自动生成getter和setter的声明 ...
- 「OC」@property @synthesize和id
一.@property @synthesize关键字 这两个关键字是编译器特性,让Xcode可以自动生成getter和setter. (一)@property 关键字 @property 关键字可以自 ...
随机推荐
- Struts2 实现文件上传
单个文件上传 关于如何创建Struts2项目:Struts2 初体验. 一.创建jsp页面: 注意!要上传文件,表单必须添加 enctype 属性,如下: enctype="multipa ...
- (转)DataTable添加行出现“该行已经属于另一个表”的错误!
1 DataTable dt1 = new DataTable(); DataTable dt2 = new DataTable(); //为dt1创建结构 DataColumn pName = ne ...
- TextField的所有属性和方法(转)
转自:http://tsyouaschen.iteye.com/blog/600255 表一 TextField 对象的方法 方法 说明TextField.addListener 加入接收触发事件如文 ...
- poj 1450 Gridland
Gridland Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- zoj1076 Gene Assembly
这道和zoj1025一样,本质是贪心算法,首先要求任意最长的序列,我们只要保证最长就行,也就是在一幅图中找一个最长的链,首先我们需要根据y排序(输入为x,y),因为y大的肯定在y小的后面,然后就直接贪 ...
- html5新增结构元素
1.article元素代表文档.页面或应用程序中独立的.完整的.可以独自被外部引用的内容.除了内容外,一个article元素还有它自己的标题(一般放在header里),有时还有自己的脚注. 2.sec ...
- Android Canvas不能换行,或者不识别\n,\r\n的解决方案
在使用Canvas绘制文本的时候,如果要绘制的字符串含有\r\n,\n换行的时候,会识别不出来,当成空格绘制出来. 解决方案: 1.使用StaticLayout来实现,具体代码如下: TextPain ...
- Web QQ自动强制加好友代码
也许见过强行聊天的代码: tencent://Message/?Uin=574201314&websiteName=www.oicqzone.com&Menu=yes 但是你应该不知 ...
- C#获取Excel Sheet名称,对特殊字符、重名进行了处理
/// <summary> /// 获取指定Excel内Sheet集合 /// </summary> /// <param na ...
- js调用打印机
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...