.@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. JVM学习笔记

    1. JVM中的直接引用和符号引用 JVM在装载class文件的时候,会有一步是将符号引用解析为直接引用的过程. 那么这里的直接引用到底是什么呢? 对于指向“类型”[Class对象].类变量.类方法的 ...

  2. yaf在windows7下32位的安装教程

    首先下载php_yaf.dll文件http://pecl.php.net/package/yaf/2.2.9/windows 打开扩展extension=php_yaf.dll 然后下载工具 http ...

  3. C# 判断字符串是否为日期格式

    判断字符串内容是否为日期格式,并返回一个日期变量 string str; DateTime dtTime; if (DateTime.TryParse(str, out dtTime)) { //st ...

  4. self.nsme 和 _name 的问题

    .h文件 @interface myclass:NSObject @property(nonatomic,retain)NSArray*MyArray; @end .m文件 @implementati ...

  5. IE6不支持position:fixed属性

    _position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop+document.d ...

  6. 【转】Android各种Adapter的用法

    转自:http://my.oschina.net/u/658933/blog/372151 Android各种Adapter的用法 发表于5个月前(2015-01-27 10:56)   阅读(143 ...

  7. C# BeginInvoke

    在用C#编写串口助手时,希望创建线程更新UI,网上有人采用BeginInvoke方法, 这里记录一下使用方法. 参考链接: http://blog.csdn.net/zaijzhgh/article/ ...

  8. Java 实现网站当前在线用户统计

    1. import java.util.HashSet; import javax.servlet.ServletContext; import javax.servlet.http.HttpSess ...

  9. c#中匿名函数lamb表达式

    c#中匿名函数lamb表达式 实例一:(其实,这样都是些语法糖) using System; using System.Collections.Generic; using System.Linq; ...

  10. 个人常用iOS第三方库以及XCode插件介绍

    第三方库 CocoaPod CocoaPod并不是iOS上的第三方库 而是大名鼎鼎的第三方库的管理工具 在CocoaPod没有出现之前 第三方库的管理是非常痛苦的 尤其是一些大型的库(比如nimbus ...