I am trying to incorporate RestKit v.20 into my iOS App. I get the proper mapping result from RKObjectRequestOperation but I can't figure out a good way to put it into a NSDictionary. I am returned an array of objects of hex values. I can get the values of all the specific items I want by using objectAtIndex: but I need a place that has all the values in its string format, not hex. I can only change from hex to string by setting the associated class equal to a single array object. I want a general list so I can predicate it for use in search.
Here is the JSON Data:
{
"carsInShop": [
{
"car": {
"id": "1",
"name": "Mercedes",
"year": "2000"
}
},
{
"car": {
"id": "2",
"name": "BMW",
"year": "2004"
}
},
{
"car": {
"id": "3",
"name": "Audi",
"year": "2001"
}
},
{
"car": {
"id": "4",
"name": "Lexus",
"year": "2011"
}
},
{
"car": {
"id": "5",
"name": "Toyota",
"year": "2006"
}
},
],
"count": 5
}
Here is where I am having code problems:
NSURL *URL = [NSURL URLWithString: @"http://localhost:8888/testphpread/index.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request
responseDescriptors:@[responseDescriptor]];
[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(@"CarsInShopArray: %@", mappingResult.array);
carsInShopArray = [mappingResult array];
CarsInShop* carsInShop = [carsInShopArray objectAtIndex:0];
NSLog(@"Loaded Car ID #%@ -> Name: %@, Year: %@", carsInShop.car.id, carsInShop.car.name, carsInShop.car.year);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(@"Operation failed with error: %@", error);
}];
This is what I get from NSLog:
CarsInShopArray: (
"CarsInShop: 0xa26b0f0",
"CarsInShop: 0xa46b2f0",
"CarsInShop: 0xa46af20",
"CarsInShop: 0xa46b7a0",
"CarsInShop: 0xa46bd90",
)
Loaded Car ID #1 -> Name: Mercedes, Year: 2000
So you see I can get individual items, but I need to access the dictionary as a whole, for use in searching.