Re: Predicate help needed
Re: Predicate help needed
- Subject: Re: Predicate help needed
- From: Adam Knight <email@hidden>
- Date: Sat, 15 Jul 2006 23:10:20 -0500
You'll want to filter by a predicate resembling this one:
NSPredicate* predicate = [NSPredicate
predicateWithFormat:@"(firstName != '') && (lastName != '')"];
NSArray* filteredArray = [[yourSet allObjects]
filteredArrayUsingPredicate:predicate];
And you now have an array of objects that match the conditions. Yay. :)
--
Adam Knight
If you're not going to stop and appreciate the scenery, you're not
going to
enjoy Myst. The same thing applies on the Mac as well. -- Rand Miller
On Jul 14, 2006, at 3:17 PM, Brad Bumgarner wrote:
Overview of project:
I am working on an app. that will allow for output to a printer
(for faxing) or email message a proof confirmation for a client
requesting work from the company I work for. Information input is
the contact person's name, their company name, phone, fax, email,
as well as the info. required for the requested job.
I would like to be able to enter the contact name in NSTokenField
and query the Address Book as the entry is being made (al a
Mail.app). I would like the organization name and phone, fax and
email fields to display the information for the current token.
Current status (I'm still learning Obj-C):
I have an NSTextfield that I currently enter the text for the
contact name. As the text is entered, the text is broken into
component parts, into an NSArray, using a space as the separator.
The Address Book is then queried for entries matching first name
and last name. (I want to be able to enter either name first so
each component is queried for both first and last names). These
results are stored in an NSMutableSet, thus eliminating duplicates.
The results are currently displayed in the run log (since I am
still in the early building/testing phase).
Now I need to filter this set to remove objects that don't contain
both (first name AND last name) OR (last name AND first name). It
seems that I should be using a predicate here but I don't
understand how to create and use them. I have read the
documentation but quickly get lost.
Here are the "players" involved in my project that I believe I need
to do the filtering:
NSArray *searchComponents;
This holds the string components (i.e.: "Brad Bumg" --> (@"Brad",
@"Bumg")) the components could be in first name first order OR last
name first order.
NSMutableSet *searchElements; // ABPerson objects matching at least
one of the searchComponents entries
Would someone help me with the filtering process?
Thanks,
Brad Bumgarner, CTA
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden