I'd like to make a Thread with multiple arguments. Is it possible? I have the function:
-(void) loginWithUser:(NSString *) user password:(NSString *) password { }
And I want to call this function as a selector:
[NSThread detachNewThreadSelector:@selector(loginWithUser:user:password:) toTarget:self withObject:@"someusername" withObject:@"somepassword"]; // this is wrong
How to pass two arguments on withObject parameter on this detachNewThreadSelect function?
Is it possible?
You need to pass the extra parameters in an object passed to withObject like so:
NSDictionary *extraParams = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"user",@"password",nil] andKeys:[NSArray arrayWithObjects:@"valueForUser",@"valueForPassword",nil]]
[NSThread detachNewThreadSelector:@selector(loginWithUser:) toTarget:self withObject:extraParams];