Starting my RestKit development, trying to make the very first request. Took this sample code from Github, modified for my classes, but after running on device I’m not seeing any signs of activity. I.e. no callbacks, no crashes, no exceptions, no logging output. Am I holding it wrong? Here’s the code:
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[FavoritePlace class]];
[mapping addAttributeMappingsFromDictionary:@{@"name": @"name", @"placeId": @"id"}];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); // Anything in 2xx
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:@"/favoritePlace/:placeID" keyPath:@"id" statusCodes:statusCodes];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://my.internal.url/v20"]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
FavoritePlace *place = [result firstObject];
NSLog(@"Mapped the place: %@", place);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failed with error: %@", [error localizedDescription]);
}];
I’m using https, as you can see – is that supported?
And as a bonus, could anyone provide the most simple code sample for 0.20 API, just to see if this thingy works at all?
In my opinion the best way to start is to check the RKTwitterCoreData app exemple, it is always updated when a new commit is made. You can see the exemple project here: https://github.com/RestKit/RestKit/tree/master/Examples/RKTwitterCoreData
From what you pasted, your code looks fine. Did you initialize RestKit in your app delegate? See here: https://github.com/RestKit/RestKit/blob/master/Examples/RKTwitterCoreData/Classes/RKTwitterAppDelegate.m
If you use Core Data, you’ll have to setup the Managed Object Store, the Persistent Store, etc.
There’s also a lot of documentation right in the API browswer, like for RKObjectManager here: http://restkit.org/api/0.20.0-pre2/Classes/RKObjectManager.html