Below is the sketch of the implementation using NSURLConnection
. Note that completionHandler
will be called when your download completes (with either OK or an error), and you can call function that processes Array
from there.
Other answers provided here are also valid and it's ultimately your call to figure out which fits your case best.
NSURLRequest* theRequest = [NSURL URLWithString:@"file to url"];
[NSURLConnection sendAsynchronousRequest:theRequest
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse* theResponse, NSData* theData, NSError* theError) {
if (theData) {
NSError* err = nil;
id Array [NSPropertyListSerialization propertyListWithData:theData
options:NSPropertyListImmutable
format:NULL
error:&err];
if ([Array isKindOfClass:[NSArray class]) {
// Do whatever you need with downloaded array
} else {
// Error -- wrong data, check err
}
} else {
// Error while downloading, check theError
}
}];