大中央调度、后台处理及应用实践
1. 大中央调度基础与界面交互优化
在开发应用时,为了确保主线程不被阻塞,从而保证界面的流畅性,我们通常会使用大中央调度(GCD)来进行后台处理。以下是一个 doWork: 方法的示例代码:
- (IBAction)doWork:(id)sender
{
self.resultsTextView.text = @"";
NSDate *startTime = [NSDate date];
dispatch_queue_t queue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSString *fetchedData = [self fetchSomethingFromServer];
NSString *processedData = [self processData:fetchedData];
NSString *firstResult = [self calculateFirstResult:processedData];
NSString *secondResult = [self calculateSecondResult:processedData];
NSString *resultsSummary = [NSString stringWithFormat:
超级会员免费看
订阅专栏 解锁全文
242

被折叠的 条评论
为什么被折叠?



