Skip to content

Instantly share code, notes, and snippets.

View shyam-habarakada's full-sized avatar
🌱
In the weeds

Shyam Habarakada shyam-habarakada

🌱
In the weeds
  • Smartsheet, 10Kft
  • Seattle, WA
  • X @shyamh
View GitHub Profile
- (void)initResKitWithCoreData
{
#if DEBUG
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
#endif
[RKRequestQueue sharedQueue].showsNetworkActivityIndicatorWhenBusy = YES;
@shyam-habarakada
shyam-habarakada / apx-restkit-error-stacktrace.txt
Created August 29, 2011 18:19
RestKit error stack trace
2011-08-29 11:14:04.308 APXClient[22687:11f03] -[NSCFString managedObjectContext]: unrecognized selector sent to instance 0xa12a0d0
2011-08-29 11:14:04.310 APXClient[22687:11f03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString managedObjectContext]: unrecognized selector sent to instance 0xa12a0d0'
*** Call stack at first throw:
(
0 CoreFoundation 0x016cb5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0181f313 objc_exception_throw + 44
2 CoreFoundation 0x016cd0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0163c966 ___forwarding___ + 966
4 CoreFoundation 0x0163c522 _CF_forwarding_prep_0 + 50
5 APXClient 0x000b338b -[RKManagedObjectMapping mappableObjectForData:] + 1225
@shyam-habarakada
shyam-habarakada / apx-restkit-mapping-problem.gdb
Created August 29, 2011 21:55
apx-restkit-mapping-problem
RKObjectMappingOperation for 'Patient' object. Mapping values from object {
patient = {
"date_of_birth" = "<null>";
displayName = "Joe Black";
"first_name" = Joe;
id = 2;
"last_name" = Black;
};
} to object <Patient: 0x5b68b40> (entity: Patient; id: 0x5b5b080 <x-coredata:///Patient/t4790029E-BA76-4D77-869D-E6BB5A80DF853> ; data: {
admissiondate = nil;

This is a title

Recently I went through the process of using RestKit and core data to implement the data stack for a new iOS application. The application needed to communicate with a JSON REST server (implemented with RoR) and cache the data obtained for faster and offline access. The app reads data from the server as well as POSTs new data to the server and makes updates to existing data.

The process of getting this to work was interesting, and not without dead-ends. I got things working in the end, and happy with the decision to go with RestKit. I filed a few bugs against RestKit along the way :-)

Below are some note that would help others who go down this path. The hope is that these tips would help avoid some of the dead-ends I hit and callout gotcha's in working with RestKit and core-data.

This is the first level of quoting.

$ curl -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"first_name":"Jenny","last_name":"McCarthy"}' http://127.0.0.1:3000/patients
HTTP/1.1 200 OK
X-Ua-Compatible: IE=Edge
Etag: "6295adeacd1c3439689e6be85996ddf5"
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
Date: Thu, 01 Sep 2011 20:23:06 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-01-10)
X-Runtime: 0.057011
Content-Length: 120
@shyam-habarakada
shyam-habarakada / restkit-mappings.md
Created September 2, 2011 20:05
mapping options

Response format A:

[
  {"id_str":"1","id":1,"last_name":"Johnson","date_of_birth":null,"display_name":"Stephanie Johnson","first_name":"Stephanie"},
  {"id_str":"2","id":2,"last_name":"Black","date_of_birth":null,"display_name":"Joe Black","first_name":"Joe"}
]

Response format B:

@shyam-habarakada
shyam-habarakada / date-time-encoding-error-with-rabl
Created September 12, 2011 19:03
date-time-encoding-error-with-rabl
OkJson::Error in Posts#index
Showing /Users/shyam/dev/apx-server/app/views/posts/index.rabl where line #1 raised:
cannot encode ActiveSupport::TimeWithZone: Fri, 09 Sep 2011 21:47:05 UTC +00:00
Extracted source (around line #1):
1: collection @posts
2:
3: extends "posts/show"
@shyam-habarakada
shyam-habarakada / rest-kit-mapping-options.js
Created September 13, 2011 23:02
rest-kit-mapping-options
/*
* RestKit QUESTION
*
* What is the correct way to map the following server response variants, and
* is there a preferred option?
*
* Also, keeping in mind that these responses can represent nested objects that need to
* be mapped to corresponding object hierarchies on the client side. I can give more
* examples of that if needed.
*
// Encounter is a managed object, and has a dynamic property called patient. of kind Patient.
// Patient is a managed object as well, and has a dynamic property id.
[objectManager.router routeClass:[Encounter class]
toResourcePath:@"/patients/:patient.id/encounters"
forMethod:RKRequestMethodPOST];
// Routing isn't resolving as expected.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<title>LDVC Seadragon Prototype</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<style type="text/css">