Complex usage of Address Book search elements via Cocoa

314 views Asked by At

I'm trying to use the ABPerson method searchElementForProperty:... to create a moderately complex search. In particular, I want to find the set of people who have an email address that ends with "foo.com", and are NOT part of the pre-populated group "My workunit".

Matching against just the email address seems to be trivial. Creating a conjunction against the (inverse of the) group membership seems impossible.

Yes, I can do this by doing the obvious explicit cross-checking myself, but if the point of having search functionality directly in Address Book is to optimize performance, wouldn't it make sense for the search facility to be sufficiently complete to be able to do this?

Thanks in advance, Tony

2

There are 2 answers

0
Alex On

You could potentially copy all the data from the address book into a Core Data store and use predicates to work with that data. Predicates tend to be very useful when building complex queries.

Predicate Programming Guide

In this case you would have to get all contacts ([[AddressBook sharedAddressBook] people]) and also have a Core Data entity called Contact (or something similar) that would save names, emails, addresses and other properties from the ABPerson object.

Having this you can probably create an NSPredicate to filter with the conditions you want.

0
carmin On

Groups reference their members according to recordId. The only way I have found to perform such an operation is here: how to find parent groups of a person. It is not a simple thing like we would like. It seems that Apple is not concerned about group searching which would be extremely useful.