So, I'm trying to return an array of Leaderboard objects from the database using the rest of the calls. didLoadObjects returns 0 objects, although the mapping seems to be correct:
RKObjectManager *svc = [RKObjectManager sharedManager]; NSString *resourcePath = leaderboardResourcePath; RKObjectMapping* mapping = [svc.mappingProvider objectMappingForClass:[Leaderboard class]]; RKObjectLoader *loader = [[RKObjectManager sharedManager] loadObjectsAtResourcePath:resourcePath objectMapping:mapping delegate:self];
Here is the didLoadObjects method
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects { if ([objectLoader.resourcePath isEqualToString:leaderboardResourcePath]) { @synchronized(standings) { standings = objects; } } }
Here is the display code:
+ (void)setMappings { //Standings mapping RKObjectMapping* leaderboardMapping = [RKObjectMapping mappingForClass:[Leaderboard class]]; [leaderboardMapping mapKeyPath:@"uname" toAttribute:@"uname"]; [leaderboardMapping mapKeyPath:@"geo" toAttribute:@"geo"]; [leaderboardMapping mapKeyPath:@"week" toAttribute:@"week"]; [leaderboardMapping mapKeyPath:@"year" toAttribute:@"year"]; [leaderboardMapping mapKeyPath:@"pts" toAttribute:@"pts"]; [[RKObjectManager sharedManager].mappingProvider addObjectMapping:leaderboardMapping]; RKObjectRouter *router = [RKObjectManager sharedManager].router; // Define a default resource path for all unspecified HTTP verbs [router routeClass:[Leaderboard class] toResourcePath:leaderboardResourcePath]; }
UPDATE
I found out that the problem is with the Geo object in the mappings. A geo object consists of three fields, each of which must also be displayed. Here is the mapping for the Geo object:
+ (void)setMappings { //Standings mapping RKObjectMapping* geoMapping = [RKObjectMapping mappingForClass:[Geo class]]; [geoMapping mapKeyPath:@"lat" toAttribute:@"lat"]; [geoMapping mapKeyPath:@"lng" toAttribute:@"lng"]; [geoMapping mapKeyPath:@"place" toAttribute:@"place"]; [[RKObjectManager sharedManager].mappingProvider addObjectMapping:geoMapping]; [[RKObjectManager sharedManager].mappingProvider setMapping:geoMapping forKeyPath:@"geo"]; } + (void)initialize{ [super initialize]; if ([self class] == [Geo class]) { [self setMappings]; } }
This causes didLoadObjects to correctly pass the objects back, but the Geo object of the Leaderboard still returns null. Thoughts?
source share