我正在通过 Apple 的 Objective-C 编程,并在此过程中进行非常简单的练习。出于某种原因,我收到一条错误消息,说Method Definition cannot be found
. 我检查了拼写和大写,该方法在.h和.m文件中。无法弄清楚它为什么这样做。
具体来说,它是说找不到“说点什么”的方法定义。这是代码:
。H
#import <Foundation/Foundation.h>
@interface XYZPerson : NSObject
@property NSString *firstName;
@property NSString *lastName;
@property NSDate *dateOfBirth;
- (void)saySomething;
- (void)sayHello;
- (void)sayShutUp;
- (void)sayHola;
+ (id)person;
@end
和.m
#import "XYZPerson.h"
@implementation XYZPerson
- (void)saySomething:(NSString *)greeting {
NSLog(@"%@", greeting);
}
- (void)sayHello {
[self saySomething:@"Hello, World!"];
}
- (void)sayHola {
[self saySomething:@"Hola, Amigos!"];
}
- (void)sayShutUp {
[self saySomething:@"Shut up!"];
}
+ (id)person {
return [[self alloc]init];
}
@end