Objective-C Passing Messages with Arguments in performSelectorOnMainThread: [closed]
-
26-06-2021 - |
Question
Need help with the syntax when the method being passed into @selector has arguments. Thanks!
//This works
dispatch_async(kBgQueue, ^{
[self performSelectorOnMainThread:@selector(hydrateList) withObject:nil waitUntilDone:YES];
});
//But what about when the method in the selector has arguments?
//This is incorrect, syntactically
dispatch_async(kBgQueue, ^{
[self performSelectorOnMainThread:@selector(hydrateListForCategory:self.categorySelected) withObject:nil waitUntilDone:YES];
});
Solution
[self performSelectorOnMainThread:@selector(hydrateListForCategory:) withObject:self.categorySelected waitUntilDone:YES];
OTHER TIPS
Hint: that's why the "withObject:" part is there.
Hint 2: Apple has pretty good docs for their frameworks.
Hint 3:
[self performSelectorOnMainThread:@selector(hydrateListForCategory:) withObject:self.categorySelected waitUntilDone:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow