@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的声明 ...
随机推荐
- java 客户端获取真实ip地址
在开发工作中,我们常常需要获取客户端的IP.一般获取客户端的IP地址的方法是:request.getRemoteAddr();但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实 ...
- 【转】在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求
http://zhoufoxcn.blog.51cto.com/792419/561934 这个需求来自于我最近练手的一个项目,在项目中我需要将一些自己发表的和收藏整理的网文集中到一个地方存放,如果全 ...
- docker jenkins
https://segmentfault.com/a/1190000003732967
- hadoop 2.4 伪分布式模式
1.core-site.xml 在<configuration></configuration>中插入 <property> <name>fs.defa ...
- iOS NSURLSession 下载
周五的时候,有个新的需求,要下载脚本,帮助玩家自动打怪,应该也是挂机的意思吧! 组长让我设计界面,让汤老师设计数据等.我觉得数据的挑战性更大一点,然后就接过来了. 自己还没有形成互联网思维,所以弄了一 ...
- c#设计模式之单例模式
单例模式(Singleton Pattern )就是为了整个应用程序的生命周期内的任何时刻,类只能创建一个实例. 单线程下的单例模式代码: public class Singleton { priva ...
- WPF数据库连接错误:The user is not associated with a trusted SQL Server connection.
我当初安装sql server的时候选的Window Authentication mode,没选SQL Server Windows Authentication. 后来做WPF时连接数据库时需要一 ...
- imx6 u-boot.bin 和 u-boot.imx
有些MFG TOOL烧录工具使用了u-boot.imx,而不是原来的u-boot.bin文件进行烧录. 这两个镜像的区别是,u-boot.bin文件编译后,会在u-boot.bin的开头添加一个大小为 ...
- json和string 之间的相互转换
json和string 之间的相互转换 <script type="text/javascript"> //先认识一下js中json function showInfo ...
- java时间戳转date(转)
1.时间戳的定义 时间戳(timestamp),通常是一个数字序列,唯一地标识某一刻的时间,指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起 ...