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中的实际用法
  • 相关阅读:
    图片上传
    解决Vuex持久化插件-在F5刷新页面后数据不见的问题
    vue登录
    拖动排序的vue组件
    vue图片懒加载
    vue中使用图片预加载
    前端架构知识体系
    html判断IE版本
    HighCharts 在IE8下饼图不显示的问题
    新一代调试王者Console
  • 原文地址:https://www.cnblogs.com/mypsq/p/5265870.html
Copyright © 2011-2022 走看看