iOS 앱에서 forecast.io API를 사용하여 3 일 특정 일기 예보를 얻습니다. 일단 내가 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);
}
, 그것은, 널 (null)로 표시 allOfIt에 대한 NSLog를, 화재 : 여기에 지금까지 가지고있는 것입니다. 내가 뭘 놓치고 있니?
3 개의 메시지가 모두 서버로 이동하여 동시에 되돌아 오기 때문에 후자는 대개 훨씬 빠릅니다. – gnasher729