zoukankan      html  css  js  c++  java
  • objective-c保护属性

    #import <Foundation/Foundation.h>
    
    @interface ClassVirable : NSObject{
        NSInteger year;//保护树形
    }
    @property int age;//不用在实现文件中写@synthesize age就会有setAge:和age方法了
    -(void)set:(NSInteger)i;
    @end
    #import "ClassVirable.h"
    
    @implementation ClassVirable
    ///Property implementation must have its declaration in interface 'ClassVirable'
    //@synthesize year;
    -(void)set:(NSInteger)i{
        self.age = i;
        year = i;
    }
    @end
    #import <Foundation/Foundation.h>
    #import "ClassVirable.h"
    int main(int argc, const char * argv[])
    {
    
        @autoreleasepool {
            ClassVirable *c = [[ClassVirable alloc]init];
            [c set:2];
            [c setAge:20];
            NSLog(@"%i",[c age]);
            NSLog(@"%i",c.age);
            //Instance variable 'year' is protected
    //        NSLog(@"%ld",(long)c->year);
        }
        return 0;
    }
  • 相关阅读:
    HTTP报文详解
    常用的HTTP协议
    URL详解
    一起切磋
    emacs使用指南
    SSH自动部署
    linux上应用随机启动
    让Maven正确处理javac警告
    最近的学习
    Java application 性能分析分享
  • 原文地址:https://www.cnblogs.com/ghgyj/p/4025659.html
Copyright © 2011-2022 走看看