I've got an NSMutableArray filled with objects of type "GameObject". GameObject has a number of properties, one of which being "gameObjectType" . "gameObjectType" is of type GameObjectTypeEnum. I want to be able to filter this NSMutableArray so only GameObjects of a certain type are returned. I've got the following in place, but it's giving me a "BAD ACCESS" error:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"gameObjectType = %@", gameObjectType];
return [gameObjects filteredArrayUsingPredicate:predicate];
Is it possible to pass a "custom" type (ie, this enum I've defined) into the predicateWithFormat call?
The string format specifier %@
indicates an object, while you're passing an integral value. You probably want to typecast the gameObjectType to an int
and use the %d
specifier. Take a look at the string format specifiers for more info.
- (NSArray *)arrayFilteredByType:(enumType)type {
//type is an NSUInteger property of the objects in the array
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"type = %d", type];
return [self.array filteredArrayUsingPredicate:predicate];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With