matthewcheok / Realm-JSON

A concise Mantle-like way of working with Realm and JSON.
MIT License
661 stars 129 forks source link

Strange Property Crash #59

Closed lucianocn closed 9 years ago

lucianocn commented 9 years ago

JSON:

     {
        "id": 318729,
        "name": "Testing",
        "waitingTime": 2114
    }

Model.h:

     #import <Realm/Realm.h>

     @interface LineTest : RLMObject
     @property NSInteger id;
     @property NSString *name;
     @property NSInteger waitingTime;   // Crash When Uncommented
     @end

If I comment the waitingTime property, REALM is importing the jSON without error. But if not, the app crashs.

Success Output:

    2015-09-24 02:12:40.454 Get In Manager[2119:5308745] result: (
        "Model {\n\tid = 318729;\n\tname = Testing;\n}"
    )

Crash (with waitingTime uncommented):

    2015-09-24 02:06:45.464 MyApp1777:5299422] *** Terminating app due to uncaught exception 'RLMException', reason: 'Missing property value'

Can it be happen due the capital letters in the middle of the property name? (waitingTime)

matthewcheok commented 9 years ago

Yes the framework assumes your server uses snake_case so you need to provide the necessary mapping:

+ (NSDictionary *)JSONInboundMappingDictionary {
  return @{
         @"id": @"id",
         @"name": @"name",
         @"waitingTime": @"waitingTime"
  };
}
lucianocn commented 9 years ago

@matthewcheok Its working! Thanks for the fast response!