The problem is that finalArray ... should only contain the name and not the image
You cannot do that with a predicate. You can filter the array on the "name" property of its elements:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains [cd] %@",self.searchBar.text];
NSArray *filteredArray = [finalArray filteredArrayUsingPredicate:predicate];
and then, if necessary, create a new array containing only the names of the objects:
NSArray *filteredNames = [filteredArray valueForKey:@"name"];
Note also, as already commented above, your code creates only a single object, which is repeatedly modified and added to the array. Since an array holds pointers to its elements, you will end with an array of identical objects.
The creation should be moved into
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"language"]) {
thename = attributeDict[@"name"];
theimage = attributeDict[@"image"];
theId = attributeDict[@"id"];
FinalObject *object = [FinalObject new];
object.name = thename;
object.image = theimage;
[finalArray addObject:object];
// ...
}
}
Update: If I understand your comment correctly, you should not create an array containing the names only. Just create the filtered array as
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains [cd] %@",self.searchBar.text];
NSArray *filteredArray = [finalArray filteredArrayUsingPredicate:predicate];
Then, in cellForRowAtIndexPath
, you access the objects properties, for example:
FinalObject *object = filteredArray[indexPath.row];
cell.textLabel.text = object.name;
// ... do something with object.image ...