问题
I load a big plist file from url and I must wait for some seconds before I can use the application. Is there some solution? How it can be loaded in background? Is GCD
what I need? How it can be implemented?
My code:
NSString *urlStr = [[NSString alloc]
initWithFormat:@"http://www.domain.com/data.xml"];
NSURL *url = [NSURL URLWithString:urlStr];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];
回答1:
You could create a new thread to do so Please check the following
//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
});
}
来源:https://stackoverflow.com/questions/10861935/load-a-big-plist-from-url-in-background