博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
@perproty and @synthesize
阅读量:4358 次
发布时间:2019-06-07

本文共 1288 字,大约阅读时间需要 4 分钟。

1.@property 是什么?    @perperty 是声明属性的语法,他可以快速方便的为实例变量创建存取器,并允许我们通过点语法使用存取器    【存取器:用于获取和设置实例变量的方法,获取实例变量值得是getter,设置实例变量存取器的是setter】    2.手工创建存取器        #import 
@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
#import "car.h" int main(int argc, const char * argv[]) { @autoreleasepool { Car *car = [[Car alloc] init]; car.carName = @"Defuli"; car.carType = @"SUB"; car.carNum = @"12"; 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 0; } mian中的实际用法

 

转载于:https://www.cnblogs.com/mypsq/p/5265870.html

你可能感兴趣的文章
将时间 '2018-08-06T10:00:00.000Z' 格式转化为本地时间
查看>>
为kubectl配置别名和命令行补齐
查看>>
解决在python中进行CGI编程时无法响应的问题
查看>>
记录一次MySQL数据库CPU负载异常高的问题
查看>>
python查看redis版本
查看>>
安装go环境
查看>>
安装kubernetes-dashboard
查看>>
从容器拷贝文件
查看>>
随笔-ansible-2
查看>>
腾讯云时间服务器
查看>>
nginx基础内容
查看>>
在CentOS 7上安装常用的YUM源
查看>>
getattr和setattr
查看>>
在CentOS6上安装mysql5.7报错
查看>>
cpu多级缓存
查看>>
使用VBA达到vlookup效果
查看>>
[已解决]报错run `npm audit fix` to fix them, or `npm audit` for details
查看>>
CUDA学习(六)之使用共享内存(shared memory)进行归约求和(M个包含N个线程的线程块)...
查看>>
CUDA学习(四)之使用全局内存进行归约求和(一个包含N个线程的线程块)
查看>>
CUDA学习(五)之使用共享内存(shared memory)进行归约求和(一个包含N个线程的线程块)...
查看>>