从背景中的URL加载一个大的plist

时间:2012-06-02 11:28:22

标签: ios xcode load plist grand-central-dispatch

我从url加载一个大的plist文件,我必须等待几秒才能使用该应用程序。有一些解决方案吗?如何在后台加载? GCD我需要什么?如何实施?

我的代码:

NSString *urlStr = [[NSString alloc] 
                    initWithFormat:@"http://www.domain.com/data.xml"];

NSURL *url = [NSURL URLWithString:urlStr];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];

1 个答案:

答案 0 :(得分:0)

您可以创建一个新线程来执行此操作 请检查以下

//Create the thread 
[NSThread detachNewThreadSelector:@selector(loadPList) toTarget:self withObject:nil];

- (void) loadPList
{
    //Load the plist
    NSString *urlStr = [[NSString alloc] 
                       initWithFormat:@"http://www.domain.com/data.xml"];

    NSURL *url = [NSURL URLWithString:urlStr];
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];

    //Update the ui
    dispatch_async(dispatch_get_main_queue(), ^{
        //Update UI if you have to
    });

}