我似乎無法繞過此錯誤;使用未聲明的標識符'ageBy'。 我不明白爲什麼得到它,因爲我有我的代碼中的導入Person.h。 感謝您的時間和任何幫助。未聲明的標識符目標C
Person.h
@interface Person : NSObject
{
int _age;
int _years;
NSString *_name;
NSString *_job;
}
-(void)setAge:(int)age;
-(int)age;
-(void)setName:(NSString *)name;
-(NSString *)name;
-(void)setJob:(NSString *)job;
-(NSString *)job;
-(NSString *)summaryString;
-(void)ageBy:(int)years;
@end
Person.m
#import "Person.h"
@implementation Person
-(void)setAge:(int)age{
_age = age;
}
-(int)age{
return _age;
}
-(void)setName:(NSString *)name{
_name = name;
}
-(NSString *)name{
return _name; }
-(void)setJob:(NSString *)job{
_job = job;
}
-(NSString *)job{
return _job;
}
-(NSString *)summaryString{
return [NSString stringWithFormat:@"The Person %@ is %d years old and is a %@",_name,_age,_job];
-(void)ageBy:(int)years{
_years = years;
_age = years + _age;
}
}
@end
你可以通過聲明的幾個屬性而不是實例變量和方法消除了80%,如果這個代碼。 – rmaddy