3 OC 属性和方法

1 OC 的属性的生成
 


@interface Student:NSObject
{

    @public
    int _no;
    int _age;
 
}

@property (nonatomic,assign)int height;

@end

 

当我们使用property 的时候,那么系统会自动的在其内部生成个属性

xcrun -sdk iphoneos clang  -arch arm64 -rewrite-objc main.m -o main.cpp

 

然后发现student 的实现是

struct Student_IMPL {
    struct NSObject_IMPL NSObject_IVARS;
    int _no;
    int _age;
    int _height;
};

 

 

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        Student *stu1 = [[Student alloc]init];
        [stu1 setHeight:5];
        [stu1 height];
        
    }
    return 0;
}

 

我们调用的set 和 get 方法,而至于属性的set 和 get 方法 ,是不存在创建的实例对象里面的,

因为如果存在实例对象中 我们我们创建10个实例对象,那么对应的方法难道要创建10份?

显然这是不现实的。