@perproty and @synthesize
.@property 是什么?
@perperty 是声明属性的语法,他可以快速方便的为实例变量创建存取器,并允许我们通过点语法使用存取器
【存取器:用于获取和设置实例变量的方法,获取实例变量值得是getter,设置实例变量存取器的是setter】 .手工创建存取器 #import <Foundation/Foundation.h> @interface Car : NSObject
{
NSString *carName;
NSString *carType;
} @property(nonatomic,strong) NSString *carName;
@property(nonatomic,strong) NSString *carType;
@property(nonatomic,strong) NSString *carNum; @end
上面的carName和carType就是类Car的属性变量,可以看到分别对这两个实例变量声明了get/set方法,即存取器 #import "Car.h" @implementation Car @synthesize carName;
@synthesize carType; @end
以上代码对存取器进行了实现 #import <Foundation/Foundation.h>
#import "car.h"
int main(int argc, const char * argv[])
{ @autoreleasepool { Car *car = [[Car alloc] init];
car.carName = @"Defuli";
car.carType = @"SUB";
car.carNum = @"";
NSLog(@"The Car name is %@ and the type is %@ and the No is %@.",car.carName,car.carType,car.carNum); [car setCarName:@"FUjian"];
[car setCarType:@"FLL"]; NSLog(@"The Car name is %@ and the type is %@",car.carName,car.carType);
}
return ;
}
mian中的实际用法
@perproty and @synthesize的更多相关文章
- 1.ios synthesize有什么作用
###1.ios synthesize有什么作用 当定义了一系列的变量时,需要写很多的getter和setter方法,而且它们的形式都是差不多的,所以Xcode提供了@property和@synthe ...
- synthesize的作用
@synthesize是对属性的实现,实际上就是制定setter和getter操作的实例变量的名称 举个栗子: @synthesize array; 默认操作的实例变量和属性同名 @synthe ...
- synthesize 与dynamic的区别
官方文档解释: @synthesize will generate getter and setter methods for your property. @dynamic just tells t ...
- IOS 关键字self,super,copy, retain, assign , readonly , readwrite, nonatomic、 @synthesize、@property、@dynamic
IOS 关键字self,super,copy, retain, assign , readonly , readwrite, nonatomic. @synth ...
- 属性(@property)、@synthesize
先前我们学的实例变量是这样的 { int _age; int _height; int age; } 后来学属性 @property int age; 看到@property 会自动编译生成某个成员变 ...
- OC- @property @synthesize
@property 1,在@interface中 2,自动生成setter和getter的声明 #import <Foundation/Foundation.h> @interface P ...
- @synthesize的正确使用方式
@synthesize的正确使用方式 一. @synthesize的错误使用方式 类1和类2是继承关系, name是类1的属性 但是类2的实现里加入了@synthesize name = _name; ...
- @synthesize vs. @dynamic
@synthesize will generate getter and setter methods and corresponding instance variable for your pro ...
- OC语言@property @synthesize和id
OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字是编译器特性,让xcode可以自动生成getter和setter的声明 ...
随机推荐
- android studio 编程中用到的快捷键
1.Ctrl+Alt+T可以把代码包在一块内,例如try/catch Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:0000000111 EndF ...
- 【转】NGUI版虚拟摇杆
http://blog.csdn.net/anyuanlzh/article/details/40107577 下面是我用nui实现的一个虚拟摇杆. 1,示图 2.代码如下,都有比较详细的注释,就不说 ...
- UBUNTU 14.04 安装 OPENCV 2.4.9
1. 从OpenCV.org 下载源代码 opencv-2.4.9.zip 2. 解压到准备好的目录 unzip opencv-2.4.9.zip 3. 进入源码目录,创建release目录 cd ...
- 通过宏定义判断是否引入的是framework,反之则使用双引号,实用!
例: #if __has_include(<TestHead/TestHead.h>) #import <TestHead/TestHead.h>#else#import &q ...
- C# 字符串的截取和替换
1.取字符串的前n个字符 (1)string str1=str.Substring(0,n); (2)string str1=str.Remove(i,str.Length-n); 2.去掉字符串的前 ...
- hdu1231最大连续子序列
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1231 #include<iostream> #include<cstdio> ...
- leap motion
体感控制器: 识别:手,手指和工具,获取位置,手势,动作 范围:倒金字塔,塔尖在设备中心,2.5cm~0.6米 坐标系统:采用右手笛卡尔积坐标系,返回的数值:毫米 摆放:绿灯朝向自己,z轴距离屏幕越来 ...
- appium testcase1(Java)
官网源码地址 https://github.com/appium/sample-code/blob/47fc0305396b8322b727820ca55a07607395040c/sample-co ...
- JavaScript学习之对象
JavaScript对象 一.对象简介 JavaScript 是面向对象的编程语言 (OOP).OOP 语言使我们有能力定义自己的对象和变量类型.注意:对象只是一种特殊的数据.对象拥有属性和方法. 1 ...
- sql server 2008语句中的go有什么用?
GO表示一个批处理的结束, SQLSERVER遇到Go以后就会将GO之前的语句作为一整批进行处理你在SSMS里执行的时候, 通常加不加都可以,但是如果实在SQLCMD下执行, GO就是一个执行命令了另 ...