我正在做Person和PersonChild類的示例。 我想知道爲什麼我可以從Person類中獲得這個Int。繼承Xcode中的其他類
//主
#import <Foundation/Foundation.h>
#import "Person.h"
#import "PersonChild.h"
int main(int argc, const char * argv[]){
@autoreleasepool {
PersonChild *Ben = [[PersonChild alloc]init];
Ben.age = 25; <-- Property 'age' not found on object of type 'PersonChild *'
[Ben printThing];
}
return 0;
}
// Person類
#import "Person.h"
@implementation Person
@synthesize age, weight;
@end
//Person.h
#import <Foundation/Foundation.h>
@interface Person : NSObject{
int age;
}
@property int age, weight;
@end
// PersonChild類
#import "PersonChild.h"
@implementation PersonChild
-(void) printThing{
NSLog(@"%i", age);
}
@end
//PersonChild.h
#import <Foundation/Foundation.h>
#import "Person.h"
@class Person;
@interface PersonChild : NSObject
-(void) printThing;
@end
謝謝!我以爲我嘗試過......我知道這是一件小事...... – DDukesterman 2013-02-23 20:41:05