Cast an NSDictionary value while applying an NSPredicate?
Posted
by RickiG
on Stack Overflow
See other posts from Stack Overflow
or by RickiG
Published on 2010-05-11T19:37:28Z
Indexed on
2010/05/11
19:44 UTC
Read the original article
Hit count: 493
Hi
I have an Array of NSDictionary objects. These Dictionaries are parsed from a JSON file. All value objects in the NSDictionary are of type NSString, one key is called "distanceInMeters".
I had planned on filtering these arrays using an NSPredicate, so I started out like this:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(distanceInMeters <= %f)", newValue];
NSArray *newArray = [oldArray filteredArrayUsingPredicate:predicate];
I believe this would have worked if the value for the "distanceInMeters" key was an NSNumber, but because I have it from a JSON file everything is NSStrings. The above gives this error:* -[NSCFNumber length]: unrecognized selector sent to instance 0x3936f00**
Which makes sense as I had just tried to treat an NSString as an NSNumber.
Is there a way to cast the values from the dictionary while they are being filtered, or maybe a completely different way of getting around this?
Hope someone can help me :)
© Stack Overflow or respective owner