私はRestKitの初心者です(iOSの経験があります)。NSArrayにRKMappingResultが入力されていないという問題があります。実際の「ブロック」にのみ入力されますが、viewDidLoad()でアクセスするために呼び出すと、nullが出力されます。
アドバイスや記事へのリンクを教えてください。
どうもありがとう!
ここに私のコードがあります -
-(void) loadData
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Venue class]];
[mapping addAttributeMappingsFromDictionary:@{
@"name": @"name", @"location.address" : @"address", @"location.city" : @"city"}];
NSString *urlString = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/search?ll=55.903324,-3.171383&categoryId=4bf58dd8d48988d18f941735&client_id=%s&client_secret=%s&v=20130717", kCLIENTID, kCLIENTSECRET];
NSURL *baseUrl = [NSURL URLWithString:urlString];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping method:RKRequestMethodAny pathPattern:nil keyPath:@"response.venues" statusCodes:nil];
NSURLRequest *request = [NSURLRequest requestWithURL:baseUrl];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
//set the array of venues to be the result of what we got back
//NSLog(@"%@", [result array]);
NSArray *venues = [result array];
self.arrayOfVenues = venues; //self.arrayOfVenues is always null when I call it in the other methods
} failure:nil];
[operation start];
}
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
NSLog(@"%@", self.arrayOfVenues);
}
- (void)viewDidLoad
{
[super viewDidLoad];
//load the venue data
self.title = @"Venues";
[self loadData];
NSLog(@"%@", self.arrayOfVenues);
}