问题描述
- Objective C中没有声明的标示符
- 实在是不知道该怎么绕过这个错误,总是说:use of undeclared identifier 'ageBy'。请高手帮我指点一下吧,先看看我的代码:
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
解决方案
你的ageBy
是在summaryString
中定义的,应该移动{}括号到@end之前,这样它就在-(void)ageBy:(int)years
中了,
-(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; }
时间: 2024-10-03 00:13:57