オブジェクトを非同期でダウンロードし、配列に保存します。次に、各オブジェクトについて、ジオコーディングを使用して座標をダウンロードし (これも非同期です)、座標である新しいパラメーターを使用して各オブジェクトのデータベースを更新します。私の方法は次のようになります。
- (void)downloadObjectsWithTitle:(NSString *)title andHandler:(void(^)(NSMutableDictionary *result))handler {
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
path:nil
parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//I get here array of objects
//now for each object I want to download geocoding localization so i called another asynchronyous method getLocationWithTitle:andHandler;
for(int i = 0; i < resutArray.count; i++) {
[self downloadLocationWithString:[dictionary objectForKey:@"string"] andHandler:^(NSMutableDictionary *result) {
//update database;
}];
}
handler(dictionary);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];
}
私の質問は、各オブジェクトの座標をダウンロードして起動する方法です。
handler(dictionary);
そのため、各座標のダウンロード (オブジェクトごと) を待ってから、メソッドを終了します (ハンドラーを起動します)。
すべての提案に感謝します。