Reputation: 616
I have a NSObject class in Xcode and the @implementation line is giving me an error; Method definition for 'initWithName:tutorID:tutorPhone:tutorEmail:' not found.
My .h file:
#import <Foundation/Foundation.h>
@interface TutorsItem : NSObject
@property (nonatomic, strong) NSString *tutorName;
@property (nonatomic) int tutorID;
@property (nonatomic, strong) NSString *tutorPhone;
@property (nonatomic, strong) NSString *tutorEmail;
- (id)initWithName:(NSString *)tutorName tutorID:(int)tutorID tutorPhone:(NSString *)tutorPhone tutorEmail:(NSString *)tutorEmail;
@end
My .m file:
#import "TutorsItem.h"
@implementation TutorsItem
@synthesize tutorName = tutorName;
@synthesize tutorID = tutorID;
@synthesize tutorPhone = tutorPhone;
@synthesize tutorEmail = tutorEmail;
- (id)initWithName:(NSString *)title subtitle:(NSString *)subtitle {
self = [super init];
if (self) {
self.tutorName = tutorName;
self.tutorID = tutorID;
self.tutorPhone = tutorPhone;
self.tutorEmail = tutorEmail;
}
return self;
}
@end
Upvotes: 0
Views: 2280
Reputation: 8511
Just so you are clear what people are try to tell you in your .h you have the following line of code
- (id)initWithName:(NSString *)tutorName tutorID:(int)tutorID tutorPhone:(NSString *)tutorPhone tutorEmail:(NSString *)tutorEmail;
but in your .m file you have this...
- (id)initWithName:(NSString *)title subtitle:(NSString *)subtitle
As you can see the 2 lines of code don't match, the compiler expects you to have a method in the .m file with the same name as you've defined in the .h. So to get rid of the error your .m file would need to have the following
- (id)initWithName:(NSString *)tutorName tutorID:(int)tutorID tutorPhone:(NSString *)tutorPhone tutorEmail:(NSString *)tutorEmail
{
self = [super init];
if (self) {
self.tutorName = tutorName;
self.tutorID = tutorID;
self.tutorPhone = tutorPhone;
self.tutorEmail = tutorEmail;
}
return self;
}
As others have also pointed out its not a good idea to have your parameter names to be the same as your properties, it just adds to confusion. The same goes for your @synthesize
This...
@synthesize tutorName = tutorName;
Might as well be this...
@synthesize tutorName;
Upvotes: 0
Reputation: 21808
Method defenition not found
is not an ERROR, it's a WARNING. And you get it cause you did not provide the definition for your method inside @implementation
section. You can still compile and run your code, but if you try to call this method your app will crash. Simply provide the definition and this warning will vanish
And btw get rid of this:
self.tutorName = tutorName;
self.tutorID = tutorID;
self.tutorPhone = tutorPhone;
self.tutorEmail = tutorEmail;
inside - (id)initWithName:(NSString *)title subtitle:(NSString *)subtitle
because what you do there makes no sense. What you do there is assign variable values to themselves
Upvotes: 0
Reputation: 676
You want to change your .m file to:
- (id)initWithName:(NSString *)tutorName tutorID:(int)tutorID tutorPhone:(NSString *)tutorPhone tutorEmail:(NSString *)tutorEmail{
self = [super init];
if (self) {
self.tutorName = tutorName;
self.tutorID = tutorID;
self.tutorPhone = tutorPhone;
self.tutorEmail = tutorEmail;
}
return self;
}
The header of the function in .m file only included the subtitle, and not tutorName , tutorId and so on. I hope this helps :)
Upvotes: 1
Reputation: 39837
The report is not an error it's a warning (unless you've enabled "warnings are errors"). It's a common warning when your @interface declares a method that your @implementation doesn't provide.
At @Wain comments, you have an init method with a very different signature in your implementation; did you intend for it to match the signature that you defined, or did you plan to provide two initializers? It's fine to have a method that doesn't appear in your @interface, but it's expected that everything presented in your @interface is intended to have an implementation as well.
Upvotes: 0