如何从我的NSURL
文件中检索结果?在此示例中completionHandler
,我的结果放在名为*localfile
. 然后我用NSXMLParserDelegate
单独的NSObject
. 一切都很好。但是我想要并且需要将数组的结果_storeProductArray
用于其他地方。
比如最后一个NSLog(@"_storeProductArray %@", _storeProductArray);
是空的……我想看NSURLSession
线程外的结果。
谢谢
NSDate *startDate1 = [NSDate date];
NSURL *storeProductURL = [NSURL URLWithString:storeProductLookupResult];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:storeProductURL];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:urlRequest
completionHandler:^(NSURL *localfile, NSURLResponse *response, NSError *error)
{
if (!error)
{
if ([urlRequest.URL isEqual:storeProductURL])
{
[productXMLQuery parseDocumentWithURL:localfile];
_storeProductArray = [productXMLQuery productArray];
NSDate *endDate1 = [NSDate date];
NSTimeInterval interval1 = [startDate1 timeIntervalSinceDate:endDate1];
NSLog(@"1 - Time took: %f", interval1);
NSLog(@"_storeProductArray %@", _storeProductArray);
}
}
} ];
[task resume];
NSLog(@"_storeProductArray %@", _storeProductArray);