I am trying to include RestKit v.20 in my iOS app. I get the correct conversion result from RKObjectRequestOperation, but I cannot find a good way to put it in an NSDictionary. I am returning an array of hexadecimal value objects. I can get the values ββof all the specific elements that I want using objectAtIndex: but I need a place that has all the values ββin its string format, and not in hex. I can only go from hexadecimal to string by setting the corresponding class to a single array object. I need a generic list, so I can predicate it for use in search.
Here are 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 }
This is where I have problems with the code:
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
So, you see that I can get individual elements, but I need to access the dictionary as a whole, for use in the search.