Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a "Method Definition not found error" and don't know why

Tags:

objective-c

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
like image 450
Joel Erickson Avatar asked Dec 20 '12 00:12

Joel Erickson


1 Answers

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.

like image 61
Jesse Rusak Avatar answered Oct 21 '22 19:10

Jesse Rusak