3

I have an array of Address Book contact dictionaries, with the dictionary for each name containing a string for the name and an array of email addresses. Here's a snippet of what the NSLog output looks like when I log the array of contacts:

{
    emails =         (
        "[email protected]"
    );
    name = "Some Name";
},
{
    emails =         (
        "[email protected]",
        "[email protected]"
    );
    name = "John Q. Public";
},
[etc.]

I want to use a predicate to search these dictionaries by email address, returning any and all entries that have at least one email address that matches the search term.

So far, I have tried the method described in this question, just using CONTAINS, like so:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"emails CONTAINS[c] %@", searchString];

but any search just returned an empty array. If I search the name field instead, like so, it works fine:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS[c] %@", searchString];

So I'm pretty sure it's specifically with searching the array. Ideas?

0

1 Answer 1

6

Aaand I figured it out. This works:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY emails CONTAINS[c] %@",currentString];

Thanks for being my rubber ducky, SO.

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.