私のiOSアプリケーションでは、forecast.io APIを使用して特定の3日間の天気予報を取得しています。すべての配列から配列を取得したら、NSMutableArrayを作成してそれらのオブジェクトをすべてそれに追加します。私が得ている問題は、予測データが取得される前にNSMutableArrayを作成しようとしていることです。ここで私はこれまで持っているものです:コードが実行されると次のメソッドを呼び出す前に完了しないコード
typedef void(^myCompletion)(BOOL);
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
[self myMethod:^(BOOL finished) {
if(finished){
NSMutableArray *allOfIt = [[NSMutableArray alloc] initWithObjects:self.weatherSaturday, self.weatherSunday, self.weatherMonday, nil];
NSLog(@"%@", allOfIt);
}
}];
}
-(void) myMethod:(myCompletion) compblock{
//do stuff
ForecastKit *forecast = [[ForecastKit alloc] initWithAPIKey:@"MY-API-KEY"];
// Request the forecast for a location at a specified time
[forecast getDailyForcastForLatitude:37.438905 longitude:-106.886051 time:1467475200 success:^(NSArray *saturday) {
// NSLog(@"%@", saturday);
self.weatherSaturday = saturday;
} failure:^(NSError *error){
NSLog(@"Daily w/ time %@", error.description);
}];
[forecast getDailyForcastForLatitude:37.438905 longitude:-106.886051 time:1467561600 success:^(NSArray *sunday) {
// NSLog(@"%@", sunday);
self.weatherSunday = sunday;
} failure:^(NSError *error){
NSLog(@"Daily w/ time %@", error.description);
}];
[forecast getDailyForcastForLatitude:37.438905 longitude:-106.886051 time:1467648000 success:^(NSArray *monday) {
// NSLog(@"%@", monday);
self.weatherMonday = monday;
} failure:^(NSError *error){
NSLog(@"Daily w/ time %@", error.description);
}];
compblock(YES);
}
、それは予測データのいずれかを取得する前に、ヌルとして示しており、allofitをのためのNSLogを発射します。私は何が欠けていますか?
3つのメッセージがすべてサーバーに送られ、同時に戻ってくるので、後者の方がずっと高速です。 – gnasher729