OC 成员变量 ( -> 使用 )

@interface Student : NSObject {
//    @public
//    @protected
//    @private
    
    // 默认的作用域是@protected
    int age;
    
    @protected
    int no;
    
    @public
    float height;
}

@property (nonatomic, assign) int age;
@end
#import <Foundation/Foundation.h>
#import "Student.h"

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        Student *stu = [[[Student alloc] init] autorelease];
        
        // 直接访问成员变量height
        stu->height = 10;
        NSLog(@"height is %.0f", stu->height);
        
        // 通过set方法访问成员变量age
        stu.age = 19;
        // 通过get方法访问成员变量age
        NSLog(@"age is %i", stu.age);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/liuwj/p/6899962.html