Reputation: 234
I am new to restkit, and i am using it in my application along with core data. I was pretty amazed with the way restkit works with core- data. It is simply amazing. But i am facing a major issue while parsing one of my webservices. The app keeps on crashing and is not able to map a value from the response. Following is my response-
[ { "id": 10, "created": "2012-10-06 13:32:09 +0000", "createdBy": null, "functionalCurrency": null, "imageUrl": null, "lat": null, "lon": null, "maxOccupancy": 0, "name": "Patio Dining", "posX": 0, "posY": 0, "reportingCurrency": null, "salesTaxRate1": 0, "salesTaxRate2": 0, "salesTaxRate3": 0, "salesTaxRate4": 0, "timezone": "-0830", "transactionalCurrency": null, "updated": "2012-10-06 13:32:09 +0000", "updatedBy": null}]
I am getting the following error.-
E restkit.object_mapping:RKObjectMappingOperation.m:262 Validation failed while mapping attribute at key path 'locationId' to value 10. Error: The operation couldn’t be completed. (Cocoa error 1610.) -[__NSCFNumber length]: unrecognized selector sent to instance 0x774e020
My location class is declared as follows-
@interface Location : NSManagedObject
@property (nonatomic,strong)NSNumber *locationId;
@property (strong, nonatomic) NSString *created;
@property (nonatomic,strong) NSString *createdBy;
@property (nonatomic,strong) NSString *functionalCurrency;
@property (nonatomic,strong) NSString *imageUrl;
@property (strong, nonatomic) NSString *lat;
@property (strong, nonatomic) NSString *lon;
I initialize the manager as follows-
RKURL *baseURL = [RKURL URLWithBaseURLString:serverUrl];
objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
objectManager.client.baseURL = baseURL;
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
[RKObjectManager setSharedManager:objectManager];
[objectManager loadObjectsAtResourcePath:[NSString stringWithFormat:@"%@", [URL resourcePath]] delegate:self];
When i try to set the locationId to NSString the RKObjectManager simply does not match any values after '9'. and when set to NSNumber it does not match any values after '2'.
Please help me. The same thing is happening for RKManagedObjectMapping and hence no data goes into my core data file.
Upvotes: 2
Views: 577
Reputation: 234
Well this is really very embarrassing, after lot of head banging finally figured out the problem. The maximum value for my locationId in core data was set to 1. Which was causing the validation error.
Upvotes: 5