Objective-C Passing Messages with Arguments in performSelectorOnMainThread: [closed]
-
26-06-2021 - |
문제
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];
});
해결책
[self performSelectorOnMainThread:@selector(hydrateListForCategory:) withObject:self.categorySelected waitUntilDone:YES];
다른 팁
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];
제휴하지 않습니다 StackOverflow