iOS中的dispatch_async和阻止 [英] dispatch_async and block in iOS

查看:136
本文介绍了iOS中的dispatch_async和阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码是什么意思?

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        TMBaseParser *parser=[[TMBaseParser alloc] init];
        parser.delegate=self;
        NSString *post =nil;
        NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding];
        [parser parseForServiceType:TMServiceCategories postdata:postData];
    });

请简要解释一下。谢谢

推荐答案

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

});

在后台线程上异步运行。这样做是因为解析数据可能是一项耗时的任务,它可能会阻止主线程停止所有动画并且应用程序无法响应。

is run asynchronously on a background thread. This is done because parsing data may be a time consuming task and it could block the main thread which would stop all animations and the application wouldn't be responsive.

如果你想要了解更多信息,请阅读有关 Grand Central Dispatch

If you want to find out more, read Apple's documentation on Grand Central Dispatch

这篇关于iOS中的dispatch_async和阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆