@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的声明 ...
随机推荐
- delphi 数组类型与数组指针的巧妙利用
{本例通过存取结构, 慢慢引入了数组类型与指针的一些使用方法; 其中六个小例子的测试内容和结果都是一样的. ---------------------------------------------- ...
- 【转】UML图中类之间的关系
原文:http://blog.csdn.net/hguisu/article/details/7609483 类与类图 1) 类(Class)封装了数据和行为,是面向对象的重要组成部分,它是具有相 ...
- 读书笔记——《图解TCP/IP》(1/4)
读书笔记——<图解TCP/IP>(1/4) 经典摘抄 第一章 网络基础知识 1.独立模式:计算机未连接到网络,各自独立使用的方式. 2.广域网 WAN 局域网 LAN 城域网 MAN 3. ...
- 【Android测试】【第一节】性能——CPU
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5065083.html 前言 本来打算写完全部的自动化测试之 ...
- Python 汉字简体和繁体的相互转换
其实利用python实现汉字的简体和繁体相互转早有人做过,并发布到github上了,地址:https://github.com/skydark/nstools/tree/master/zhtools ...
- php--tp继承公共的控制器
- 简单的form表单
效果 html <ul class="edit_list"> <li><em>*</em><span class=" ...
- pickle 数据对象的序列化和反序列化
python的pickle模块实现了基本的数据序列和反序列化.通过pickle模块的序列化操作我们能够将程序中运行的对象信息保存到文件中去,永久存储:通过pickle模块的反序列化操作,我们能够从文件 ...
- JQuery 方法简写
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- Hashtable,HashMap,Dictionary的区别
Hashtable和HashMap的区别:1.Hashtable是基于Dictionary类的,HashMap是Java 1.2引进的Map接口的一个实现,c#中无HashMap2.Hashtable ...