Restkit with Blocks를 사용하여 응답을 기다리고 있습니다.iOS RestKit Blocks
예 :
내 블록 요청NSArray *myArray = ["RESULT OF REST-REQUEST"];
// Working with the array here.
하나 :
당신은 비동기 될 이미지지고 있기 때문에이 방법에 아무것도 반환하지 수- (UIImage*)getPhotoWithID:(NSString*)photoID style:(NSString*)style authToken:(NSString*)authToken {
__block UIImage *image;
NSDictionary *parameter = [NSDictionary dictionaryWithKeysAndObjects:@"auth_token", authToken, nil];
RKURL *url = [RKURL URLWithBaseURLString:@"urlBase" resourcePath:@"resourcePath" queryParameters:parameter];
NSLog(@"%@", [url absoluteString]);
[[RKClient sharedClient] get:[url absoluteString] usingBlock:^(RKRequest *request) {
request.onDidLoadResponse = ^(RKResponse *response) {
NSLog(@"Response: %@", [response bodyAsString]);
image = [UIImage imageWithData:[response body]];
};
}];
return image;
}
무엇이 당신의 질문입니까? – Till
응답이 도착하기 전에 메서드가 끝나기 때문에 Array가 null이됩니다 ... 어떻게 응답을 기다릴 수 있습니까? 나는 그것이 블록으로 작동 할 것이라고 생각했다. – Maik639