構造方法

person.h

#import <Foundation/Foundation.h>

@interface Person : NSObject
@property int age;
@property id obj;
@end

person.m

#import "Person.h"

@implementation Person

@end


main函數

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

    @autoreleasepool {
        Person *p = [Person new];
        //[p fsdfdsfd];
        
        NSObject *o = [Person new];
        
        
        // id  == NSObject *
        // 萬能指針,能指向\操作任何OC對象
        id d = [Person new];
        
        [d setAge:10];
        
        [d setObj:@"321423432"];
        
        NSLog(@"%d", [d age]);
    }
    return 0;
}


發佈了59 篇原創文章 · 獲贊 5 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章