Created
July 30, 2012 19:55
-
-
Save ryatkins/3209606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURLString:@"http://mysite.com/"]; | |
// Core Data store | |
RKManagedObjectStore* objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"RKData.sqlite"]; | |
objectManager.objectStore = objectStore; | |
// Activity indicator | |
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES; | |
// MAPPING - Model (detail item) | |
RKManagedObjectMapping* modelMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Model" inManagedObjectStore:objectManager.objectStore]; | |
modelMapping.primaryKeyAttribute = @"modelID"; | |
[modelMapping mapKeyPath:@"id" toAttribute:@"modelID"]; | |
[modelMapping mapKeyPath:@"title" toAttribute:@"title"]; | |
[modelMapping mapKeyPath:@"image" toAttribute:@"image"]; | |
[objectManager.mappingProvider registerMapping:modelMapping withRootKeyPath:@"model"]; | |
[objectManager.mappingProvider setObjectMapping:modelMapping forResourcePathPattern:@"json.php" withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath){ | |
return [Model fetchRequest]; | |
}]; | |
// MAPPING - Category (Master) | |
RKManagedObjectMapping* categoryMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Category" inManagedObjectStore:objectManager.objectStore]; | |
categoryMapping.primaryKeyAttribute = @"categoryID"; | |
[categoryMapping mapKeyPath:@"id" toAttribute:@"categoryID"]; | |
[categoryMapping mapKeyPath:@"title" toAttribute:@"title"]; | |
[categoryMapping mapKeyPath:@"image" toAttribute:@"image"]; | |
[categoryMapping mapRelationship:@"models" withMapping:modelMapping]; | |
[objectManager.mappingProvider registerMapping:categoryMapping withRootKeyPath:@"category"]; | |
[objectManager.mappingProvider setObjectMapping:categoryMapping forResourcePathPattern:@"json.php" withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath){ | |
return [Category fetchRequest]; | |
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"category": | |
{"id":2,"title":"Your Models", | |
"models":[ | |
{"id":23,"title":"Cowboy","image":"Cowboy.png"}, | |
{"id":24,"title":"Lizard","image":"Lizard.png"} | |
] | |
} | |
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[self loadDetailItem]; | |
} | |
- (void)loadDetailItem { | |
RKObjectManager* objectManager = [RKObjectManager sharedManager]; | |
[objectManager loadObjectsAtResourcePath:@"json.php" delegate:self]; | |
} | |
- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects { | |
NSFetchRequest* fetchRequest = [Category fetchRequest]; | |
self.categories = [[Category objectsWithFetchRequest:fetchRequest] retain] ; | |
[self.tableView reloadData]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you get it working?