让我们有一个场景如下,
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Doing some DB operation or Server call
// After getting result i am making UI update in main thread
[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:YES];
});
或
通过类似
的方法在后台调用执行选择器- (void)callingWSMethod {
[self performSelectorInBackground:@selector(myMethod) withObject:nil];
}
- (void)myMethod {
// Doing some DB operation or Server call
dispatch_async(dispatch_get_main_queue(), ^{
// After getting result i am making UI update in main thread
});
}
我可以将performSelector和GCD结合使用吗?
以上两种制作后台线程和主线程调用的类型都会得到相同的结果吗? 感谢。