-1

I want to pass two arguments to method with NSThread. I tried using this third answer. But unfortunatlly that code was not working well because andKeys: method is not available.

   [NSThread detachNewThreadSelector:@selector(DownloadCheckServerPath:DirectoryName:) toTarget:self withObject:"How to pass two objects"];

So how should I called -(void)DownloadCheckServerPath:(NSString *)serverPath DirectoryName:(NSString *)directoryName this method in Sector through NSThread. ?

Community
  • 1
  • 1
Himesh
  • 458
  • 1
  • 3
  • 15
  • 1
    [this question has already been asked and answered before](http://stackoverflow.com/questions/8439052/ios-how-to-implement-a-performselector-with-multiple-arguments-and-with-afterd/8439084#8439084) – Michael Dautermann Feb 07 '13 at 07:39

2 Answers2

0

You can't pass multiple arguments to a method which is invoked by this message send. Workaround: use collections. One argument is more than enough.

- (void)reallyCallMethod:(NSDictionary *)dict
{
    [self downloadCheckServerPath:dict[@"path"] directoryName:dict[@"dir"]];
}

[NSThread detachNewThreadSelector:@selector(reallyCallMethod:)
                         toTarget:self
                       withObject:@{ @"path" : @"/foo/bar", @"dir" : @"baz" }];

Also: don't begin selector names with capital letters. That's for classes only (and it's really ugly, isn't it?)

  • yesh! Now function is working fine. Thankz for the answer. Still I am beginner of the objective c. that's y. :) – Himesh Feb 07 '13 at 08:38
0

In such cases I have typically created an NSDictionary and passed that. In the function I read the dictionary and get all the elements that I need.