Karan
Karan

Reputation: 15104

Unrecognized selector sent to instance on constructor

I am getting the famous "unrecognized selector sent to instance" on my constructor. Potentially something very simple I am missing.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Problem on the next line:

    UserFetcher* userFetcher = [[UserFetcher alloc] initWithEmail:[self email] AndPassword:[self password]]; 

    [userFetcher fetch];
}

UserFetcher.h

-(id)initWithEmail:(NSString*)theEmail AndPassword:(NSString*)thePassword;

-(void)fetch;

UserFetcher.m

-(id)initWithEmail:(NSString*)theEmail AndPassword:(NSString*)thePassword AndDelegate: (id<UserFetcherDelegate>)theDelegate;
{
    if ([super init])
    {
        email = theEmail;
        password = thePassword;
    }
    return self;
}


-(void) fetch {...}

Error

2012-07-14 22:15:12.726 Project1[38478:c07] -[UserFetcher initWithEmail:AndPassword:]: unrecognized selector sent to instance 0x7af2ff0

Any ideas what is missing?

Upvotes: 1

Views: 415

Answers (1)

MByD
MByD

Reputation: 137392

You forgot the AndDelegate: (id<UserFetcherDelegate>)theDelegate; part. Also, remove the ; from the end of the line (in the implementation). Should probably be:

-(id)initWithEmail:(NSString*)theEmail AndPassword:(NSString*)thePassword
{
    if ([super init])
    {
        email = theEmail;
        password = thePassword;
    }
    return self;
}

Upvotes: 2

Related Questions