.@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. 1.ios synthesize有什么作用

    ###1.ios synthesize有什么作用 当定义了一系列的变量时,需要写很多的getter和setter方法,而且它们的形式都是差不多的,所以Xcode提供了@property和@synthe ...

  2. synthesize的作用

    @synthesize是对属性的实现,实际上就是制定setter和getter操作的实例变量的名称   举个栗子: @synthesize array;  默认操作的实例变量和属性同名 @synthe ...

  3. synthesize 与dynamic的区别

    官方文档解释: @synthesize will generate getter and setter methods for your property. @dynamic just tells t ...

  4. IOS 关键字self,super,copy, retain, assign , readonly , readwrite, nonatomic、 @synthesize、@property、@dynamic

    IOS 关键字self,super,copy, retain, assign , readonly , readwrite, nonatomic.                     @synth ...

  5. 属性(@property)、@synthesize

    先前我们学的实例变量是这样的 { int _age; int _height; int age; } 后来学属性 @property int age; 看到@property 会自动编译生成某个成员变 ...

  6. OC- @property @synthesize

    @property 1,在@interface中 2,自动生成setter和getter的声明 #import <Foundation/Foundation.h> @interface P ...

  7. @synthesize的正确使用方式

    @synthesize的正确使用方式 一. @synthesize的错误使用方式 类1和类2是继承关系, name是类1的属性 但是类2的实现里加入了@synthesize name = _name; ...

  8. @synthesize vs. @dynamic

    @synthesize will generate getter and setter methods and corresponding instance variable for your pro ...

  9. OC语言@property @synthesize和id

    OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字是编译器特性,让xcode可以自动生成getter和setter的声明 ...

随机推荐

  1. sql server 数据库连接配置在外面 如何读取

    注意:web运行读取要把配置文件放在WEB-INF下面 Driver=com.microsoft.sqlserver.jdbc.SQLServerDriverurl=jdbc:sqlserver:// ...

  2. day08

      软件系统体系结构   常见软件系统体系结构B/S.C/S 1.1 C/S C/S结构即客户端/服务器(Client/Server),例如QQ: 需要编写服务器端程序,以及客户端程序,例如我们安装的 ...

  3. php获得文件夹下所有文件的递归算法

    function my_scandir($dir){ $files=array(); if(is_dir($dir)) { if($handle=opendir($dir)) { while(($fi ...

  4. Java高级之虚拟机加载机制

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 1.0版本:2016-05-21 SubClass!! 执行结果说明一个问题:子类调用父类变量的时候 ...

  5. 添加事件(jquery)

    对盒子内部的盒子添加跟本身盒子相同的事件的时候,需要小心谨慎一点. 诸如: 从表象上看似乎没有什么太大问题,但是却存在一个致命的问题,就是每次点击box的时候,都会给test添加一个点击事件,而添加的 ...

  6. SIP学习(实例详解)

    本文摘自:http://blog.chinaunix.net/uid-20655530-id-1589483.html 学习 SIP 协议最快捷的方法是通过范例来学习, 找到了一个完整的呼叫流程,le ...

  7. Mac下安装和配置mongoDB

    mac下的mongodb下载安装比较简单,主要有两种方式,一种是下载压缩包解压,另一种是通过npm或者homebrew命令安装,这里就不赘述了, 复杂的在于mongodb运行环境的配置(若未配置运行环 ...

  8. xcode7的那些坑-“Your binary is not optimized for iPhone 5” (ITMS-90096) when submitting

    用Xcode7向App Store提交二进制文件是,提示ERROR ITMS-90096:"You binary is not optimized for iPhone 5...." ...

  9. sqlserver 视图能否有变量

    不能,sqlserver 视图一般不能有变量,也不能带存储过程

  10. JMeter学习-003-JMeter与LoadRunner的异曲同工

    本节主要对 JMeter 与 LoadRunner 的优缺点进行概要的总结,若有不足之处,敬请指正,不胜感激! 同时,我也不得不承认,在对 JMeter 和 LoadRunner 进行比较时,我个人的 ...