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中的实际用法
  • 相关阅读:
    AutoComplete控件
    META httpequiv 大全
    十四条必知的手机电池充电技巧
    什么是套接字
    理解HTTP session原理及应用
    Adodb.Stream取得图像的高宽
    微软Windows 7测试版下载网上泄露
    Oracle新手學習
    Oracle字符串函数
    Oracle的Window服务启动时并不启动实例
  • 原文地址:https://www.cnblogs.com/mypsq/p/5265870.html
Copyright © 2011-2022 走看看