2

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];
Daniel Kamil Kozar
  • 18,476
  • 5
  • 50
  • 64
Pavel Kaljunen
  • 1,291
  • 2
  • 26
  • 53

1 Answers1

0

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
    });

}
Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56