Anil
Anil

Reputation: 272

NSPredicate to filter Getting No Results

I am trying to predicate the array with this -(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text {

if(text.length == 0)
{
    isFiltered = FALSE;
}
else
{
    isFiltered = true;
    filteredListCustomersArray = [[NSMutableArray alloc]initWithCapacity:[customersArray count]];

    [filteredListCustomersArray removeAllObjects];
    NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"SELF.text contains[c] %@",text];
    filteredListCustomersArray = [NSMutableArray arrayWithArray:[customersArray filteredArrayUsingPredicate:filterPredicate]];
    searchText=text;
}
[customerstableView reloadData];
}

I am Unable to get the results. Please help me in this,

<__NSArrayM 0x608000458480>(
{
    FLD =     (
                {
            NAME = BPCNUM;
            TYPE = Char;
            text = ACTR001;
        },
                {
            NAME = BPCNAM;
            TYPE = Char;
            text = "Regal Enterprises";
        },
                {
            NAME = BPCSHO;
            TYPE = Char;
            text = Regal;
        }
    );
    NUM = 1;
},
{
    FLD =     (
                {
            NAME = BPCNUM;
            TYPE = Char;
            text = ACTR003;
        },
                {
            NAME = BPCNAM;
            TYPE = Char;
            text = "Mace Supplies";
        },
                {
            NAME = BPCSHO;
            TYPE = Char;
            text = Mace;
        }
    );
    NUM = 2;
})

Here I want text = "Regal Enterprises" for predicate

Upvotes: 3

Views: 103

Answers (1)

Lal Krishna
Lal Krishna

Reputation: 16190

Update your predicate:

NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@" ANY FLD.text contains[c] %@", text];
filteredListCustomersArray = [[customersArray filteredArrayUsingPredicate:filterPredicate] copy];

Upvotes: 2

Related Questions