0

It is possible to filter an array of strings as follows:

NSArray *array =  @[@"honda",@"toyota",@"ford"];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@",@"ford"];
NSArray *filtered = [array filteredArrayUsingPredicate:pred];

I want to search an array that contains arrays of two strings by the values for the first of the strings. So for:

NSArray *cars = @[@[@"honda",@"accord"],@[@"toyota",@"corolla"],@[@"ford",@"explorer"]];

I want to search the first dimension (honda, toyota, ford) for @"ford"

Is there a way to tell the predicate I want to search on only the first attribute and return matching elements of the array?

0

1 Answer 1

1

Well here is the pred you need.

     NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF[FIRST] contains[cd] %@", @"ford"];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.