I have the following setup:
@interface Item : NSObject { NSInteger *item_id; NSString *title; UIImage *item_icon; } @property (nonatomic, copy) NSString *title; @property (nonatomic, assign) NSInteger *item_id; @property (nonatomic, strong) UIImage *item_icon; - (NSString *)path; - (id)initWithDictionary:(NSDictionary *)dictionairy; @end
and
#import <Foundation/Foundation.h> #import "Item.h" @interface Category : Item { } - (NSString *)path; @end
I have an array with instances of a category (called "categories") that I would like to take on a single item based on item_id. Here is the code I use for this:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"item_id == %d", 1]; NSArray *filteredArray = [categories filteredArrayUsingPredicate:predicate];
This results in the following error:
* Application termination due to the uncaught exception "NSUnknownKeyException", reason: "[valueForUndefinedKey:]: this class is not a key value compatible with the encoding for the item_id key element. '
How can I fix this and what am I doing wrong? the properties are synthesized, and I can access and set the item_id property in the instances of the category.
source share