How can I send multiple objects using performSelectorOnMainThread

I have two objects: NSData and the other is NSString. I want to send these two objects using perfomSelectorOnMainThread. How can i do this?

+5
source share
2 answers

If you are using Xcode 4.4 and later, you can simply:

[self performSelectorOnMainThread:@selector(myMethod:) withObject:@[objectA,objectB] waitUntilDone:NO];

If your version of Xcode is older then 4.4 use

[self performSelectorOnMainThread:@selector(myMethod:) withObject:[NSArray arrayWithObjects:objectA, objectB, nil] waitUntilDone:NO];

These are your selection methods:

-(void)myMethod:(NSArray*)array{

   ObjectA *objA = [array objectAtIndex:0];
   ObjectB *objB = [array objectAtIndex:1];

}
+11
source

You can use the following code:

[self performSelector:@selector(yourSelectorMethod) withObject:[NSMutableArray arrayWithObjects:@"object1",@"object2", nil]];
+1
source

All Articles