Dejell
Dejell

Reputation: 14317

Getting ordered keys from OrderDictionary

I saw some post to use this Ordered Dictionary solution in order to keep NSDictionary ordred.

It saves it in the same order that I get it from json object, but since I need to use the values for a UIPickerView, I wrote the following:

 OrderedDictionary *countryStates = [businessInfo objectForKey:@"allowedStates"];

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
        NSString *stateShort = [countryStates keyAtIndex:row ];
        return [countryStates objectForKey:stateShort];
}

However, I get:

[__NSCFDictionary keyAtIndex:]: unrecognized selector sent to instance 
  1. Why do I get it?
  2. In what other way I can use the ordered dictionary for UIPickerView without ruining the order?

Upvotes: 0

Views: 89

Answers (1)

rems4e
rems4e

Reputation: 3172

You get this error because the object associated to the @"allowedStates" in businessInfo is only a NSDictionay. You should use OrderedDictionary's + (id)dictionaryWithDictionary:(NSDictionary *)dict method to create a new object and then manipulate it.

Upvotes: 2

Related Questions