Search code examples
iphonecocoa-touchnsarraynspredicate

NSpredicate to filter the Array of Elements that has substrings


I have written NSPredicate to filter the elements .

-(void)filterResult:(NSMutableArray*)array
{
    search=TRUE;
    filteredCategoryList=[[NSArray alloc]init];


    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"roles beginsWith %@ ||     UserResponseDetails IN %@ ",array,array];
    filteredCategoryList = [MembersList filteredArrayUsingPredicate:predicate]; 
    [filteredCategoryList retain];
}

The Problem is I am getting one of the string like "sample;Example" in Roles and others are single string. How to write the Predicate condition to get the Element for Sample,Example,sample and Example. .


Solution

  • I got a solution that I have to use 'contains' keyword instead of 'beginswith' in the predicate.