I am devoleping an application for creating a search bar above contacts list.If i press the search bar app gets crashed .I debugged the application and found that the crash occuars at this line. filteredCandyArray = [NSMutableArray arrayWithArray:[candyArray filteredArrayUsingPredicate:predicate]];
What I'm doing in my program is I'm fetching all contacts(name,no.and image) and adding to an array(candyArray) .But when i try to do an NSPredicate operation,i get this message and application crashes by giving the below message.
wetwert[2380:60b] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.' * First throw call stack: (0x2d51ae83 0x378776c7 0x2d51ab89 0x2ded6e3f 0x2de3c139 0x2de7a3f7 0x2de79fb5 0x2de79083 0x2de7901f 0x2de78e2d 0x27d23 0x27f37 0x2fe92b79 0x2fcd3da3 0x2fcd3d3f 0x2fcd3d13 0x2fcbf743 0x2fe928ed 0x2fcdd8b1 0x2fe53b67 0x2fe5310f 0x2fe92727 0x2fe52e2d 0x2de49aa5 0x2fce1485 0x2fe52d5f 0x2fcc9049 0x2defee4b 0x2d4e5f1f 0x2d4e53e7 0x2d4e3bd7 0x2d44e471 0x2d44e253 0x321882eb 0x2fd03845 0x28451 0x37d70ab7) libc++abi.dylib: terminating with uncaught exception of type NSException
I'm giving the code for adding to array.below
for (int i=0; i<_contactsarray.count; i++) {
[candyArray addObject:[store candyofcategory:[_contactsarray objectAtIndex:i] phone:[_numbersarray objectAtIndex:i] image:[_imagesarray objectAtIndex:i]]];
where the 3 arrays contain name,phone no . and images. The method which gets called is shown below.
+(id)candyofcategory:(NSString *)name phone:(NSString *)phone image:(UIImage *)image{
store *newstore=[[self alloc]init];
newstore.c_name=name;
newstore.c_phone=phone;
newstore.cnt_image=image;
return newstore;
}
this method is in a class 'store' which is of NSObject class.Im able to fetch data and display in a tableview,but when i call the predicate operation on this array ,i get a crash.Any ideas on the problem? Im adding the Predicate method below
-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {
// Update the filtered array based on the search text and scope.
// Remove all objects from the filtered search array
[self.filteredCandyArray removeAllObjects];
// Filter the array using NSPredicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",searchText];
filteredCandyArray = [NSMutableArray arrayWithArray:candyArray];
filteredCandyArray = [NSMutableArray arrayWithArray:[candyArray filteredArrayUsingPredicate:predicate]];
}