zoukankan      html  css  js  c++  java
  • @perproty and @synthesize

    1.@property 是什么?
        @perperty 是声明属性的语法,他可以快速方便的为实例变量创建存取器,并允许我们通过点语法使用存取器
        【存取器:用于获取和设置实例变量的方法,获取实例变量值得是getter,设置实例变量存取器的是setter】
        
    2.手工创建存取器
        
        #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 = @"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中的实际用法
  • 相关阅读:
    bash中执行SQL语句返回一个值
    对机器特定端口增加网络延迟
    修改jmeter的界面文字大小和语言
    pip3 安装一直报错ssl问题,重装python3
    robotframework学习
    jmeter
    python3向oracle插入数据
    oracle使用时注意
    人心惟危,道心惟微,惟精惟一,允执厥中。
    vim 离线安装 .tar.gz 源码程序
  • 原文地址:https://www.cnblogs.com/mypsq/p/5265870.html
Copyright © 2011-2022 走看看