i have a NSArray containing some NSDictionaries which themselves also include a NSDictionary.
NSDictionary *dict1 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"cover" forKey:@"type"] forKey:@"image"];
NSDictionary *dict2 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"cover" forKey:@"type"] forKey:@"image"];
NSDictionary *dict3 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"back" forKey:@"type"] forKey:@"image"];
NSDictionary *dict4 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"cover" forKey:@"type"] forKey:@"image"];
NSArray *myArray = [NSArray arrayWithObjects:dict1, dict2, dict3, dict4, nil];
is there a way to filter myArray for all Image-Dictionaries where the type is f.e. “cover” using a NSPredicate?
tried predicates like
predicateWithFormat:@"(SELF.image.type == %@)", @"cover"]
or
predicateWithFormat:@"(image.type == %@)", @"cover"]
but without success.
thanks in advance! leave a comment if something is unclear
// edit
so
NSPredicate *p = [NSPredicate predicateWithFormat:@"image.type == %@", @"cover"];
is working. but in my case i want to sort out size == original. what i did is
NSPredicate *p = [NSPredicate predicateWithFormat:@"image.size == %@", @"original"];
but then my app crashes with
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSSymbolicExpression length]: unrecognized selector sent to instance
and pointing to my filteredArrayUsingPredicate method. i cannot see any difference between type and size. see my NSLog of my Array here
(
{
image = {
height = 1500;
id = 4e5808765e73d607350059b4;
size = original;
type = poster;
url = "someurl";
width = 1000;
};
},
{
image = {
height = 750;
id = 4e5808765e73d607350059b4;
size = mid;
type = poster;
url = "someurl";
width = 500;
};
},
anybody knows why it crashes when i try to use size instead of type ?
The following code worked for me: