我正在通过Objective-C进行Apple的编程,并在此过程中进行非常简单的练习.出于某种原因,我收到一条错误,指出无法找到方法定义.我检查了拼写和大写,方法是在.h和.m文件中.无法弄清楚它为什么这样做.
具体来说,无法找到“Say Something”的方法定义.这是代码:
.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
还有他们
#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