I am going through Apple's Programming with Objective-C and doing the very simple exercises along the way. For some reason I am getting an error saying that a Method Definition cannot be found
. I've checked for spelling and caps and the method is both in the .h and .m files. Can't figure out why it's doing it.
Specifically it is saying that the method definition for 'Say Something' cannot be found. Here is the code:
.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
and the .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
A method named saySomething:
is different than a method named saySomething
. The former takes an argument, and the latter does not. You'll have to change the declaration in your header file to include an argument. i.e. change:
- (void)saySomething;
to:
- (void)saySomething:(NSString *)greeting;
So that it matches your implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With