I'm having a problem mapping a JSON array of strings with no key paths using RestKit 0.20.3. My classes are based on the the example in the RestKit wiki.
JSON:
"feature_list":{
"property":["test","test ","test","test"],
"street":["test1","foo","bar"],
"garden":["foo","bar"],
"other":["foo","bar", "test2"]
}
Classes:
@interface FeatureList : NSManagedObject
@property(nonatomic, strong) NSSet *property;
@property(nonatomic, strong) NSSet *street;
@property(nonatomic, strong) NSSet *garden;
@property(nonatomic, strong) NSSet *other;
@end
@interface Feature : NSManagedObject
@property(nonatomic, strong) NSString *featureType;
@end
Mapping Setup:
+ (RKMapping *)featureListMapping {
RKObjectMapping *mapping = [RKEntityMapping mappingForEntityForName:@"FeatureList" inManagedObjectStore:objectStore];
[mapping addRelationshipMappingWithSourceKeyPath:@"property" mapping:[self featureMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:@"street" mapping:[self featureMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:@"garden" mapping:[self featureMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:@"other" mapping:[self featureMapping]];
}
+ (RKMapping *)featureMapping {
RKObjectMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Feature" inManagedObjectStore:objectStore];
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"featureType"]];
return mapping;
}
When debugging the feature.featureType object in Xcode, a RKMappingSourceObject object is returned with the value stored in an object property, which I can't access. When printing feature.featureType.class, NSCFString is printed.
for (Feature * feature in featureList.property)
{
//feature.featureType is a RKMappingSourceObject in the debugger
NSString *featureStr = feature.featureType.class; //prints NSCFString
}
Log output:
Mapped attribute value from keyPath '(null)' to 'featureType'. Value: test ({
HTTP = {
request = {
URL = "http://localhost:3000/api/v1/test";
headers = {
};
method = GET;
};
response = {
URL = "http://localhost:3000/api/v1/test";
headers = {
"Cache-Control" = "max-age=0, private, must-revalidate";
"Content-Type" = "application/json; charset=utf-8";
Etag = "\"193d0f470155872e5b36e9f7586c0c8f\"";
"Proxy-Connection" = Close;
Server = "thin 1.5.0 codename Knife";
"X-Request-Id" = 0e4de78e656ef2165699385695cdfe75;
"X-Runtime" = "0.092788";
"X-UA-Compatible" = "IE=Edge";
};
};
};
mapping = {
collectionIndex = 1;
rootKeyPath = response;
};
})
Any suggestions would be appreciated, Thanks
Basically, you can use any method on the returned proxy object other than description. That means not supplying it as a variable to NSLog.
The true objects will be stored into the data store. Depending on what you need to do you may want to go and retrieve them directly (by fetching or using the managed object id).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With