私はProductData
という配列を持っていますが、それらをcategory
に基づいてフィルタリングし、次のように適用しました。Predicate
が返されました。キャッチされない例外により「NSUnknownKeyException」、 理由にアプリを終了NSPRedicate値ForUndefinedKey
pTempElements =[[NSMutableArray alloc] initWithArray: [self.pElements filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"category = %@", @"4"]]];
:「[valueForUndefinedKeyは:]:このクラス は、キー値コーディング準拠のキーカテゴリのではありません。」
ここではpElements
po self.pElements
<__NSArrayM 0x174241e30>(
<ProductData: 0x17427ce00>,
<ProductData: 0x17427cd80>,
<ProductData: 0x17427ce40>,
<ProductData: 0x17427ce80>,
)
の見落としであるProductData.m
#import "ProductData.h"
@implementation ProductData
@synthesize pId, pImage, pPrice, pName, pCategory
-(id)initWithDictionary:(NSDictionary *)aDict{
self = [self init];
if (self){
self.pId = [aDict objectForKey:@"id"];
self.pPrice = [aDict objectForKey:@"price"];
self.pImage = [aDict objectForKey:@"imagePath"];
self.pCategory = [aDict objectForKey:@"category"];
self.pName = [aDict objectForKey:@"name"];
}
return self;
}
以下のようにコードを書き直す必要がありますか? pTempElements = [[NSMutableArray alloc] initWithArray:[self.pElements filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@ "pCategory ==%@"、@ "4"]]]; –
はい、うまくいきました。 – hotspring