我正在为 Person 和 PersonChild 类做一个例子。我想知道为什么我可以从 Person 类中得到这个 Int 。
//主要的
#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;
}
//人物类
#import "Person.h"
@implementation Person
@synthesize age, weight;
@end
//人.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