Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c using thread causes: target does not implement selector

Tags:

objective-c

As I am pretty new to ObjC I'm stuck to the following issue:

I have a function downloadFile

-(void) downloadFile:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options      
{
    //do stuff
}

I want to start this as a thread, and therefore I use this line of code:

NSThread* dLoad = [[NSThread alloc] initWithTarget:self selector:@selector(downloadFile:) object:nil];
[dLoad start];  

It throws me the following error:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSThread initWithTarget:selector:object:]: target does not implement selector (*** -[LaunchDownload downloadFile:])'

What am I missing over here?

like image 437
Wouter A Avatar asked Feb 03 '11 09:02

Wouter A


2 Answers

I believe you're not providing enough arguments to your thread. The method you implemented has the signature downloadFile:withDict:, but you're only providing downloadFile:. You should give it the correct selector name.

Keep in mind that you will probably run into trouble anyway - the NSThread class reference specifies that methods you call this way must take only one argument. I'd recommend either converting your two arguments to a single NSDictionary that your method parses out or rethinking how you're dispatching this thread.

like image 118
Tim Avatar answered Nov 17 '22 15:11

Tim


The method name is downloadFile:withDict: and not downloadFile: .

like image 32
Philipp Avatar answered Nov 17 '22 14:11

Philipp