Re: Newbe Question: Searching Address Book
Re: Newbe Question: Searching Address Book
- Subject: Re: Newbe Question: Searching Address Book
- From: Xavier Elizalde <email@hidden>
- Date: Wed, 3 May 2006 03:29:34 +1000
I'm really new to Objective-C myself and I don't know if this will
help, but here is a code example which was one of the exercises in
the book I was reading. It list the names in the Address Book. It is
a Foundation Tool project and the Address Book framework has to be
added to the project. You can right click (or ctrl-click) on the
External Frameworks and Libraries folder in the project window ->
"Add" -> "Existing Frameworks..." and navigate to the
"AddressBook.framework" to do that. The program can output a bunch of
(null)s for entries that don't have first and last names, like
Address Book entries for companies.
#import <Foundation/Foundation.h>
#import <AddressBook/AddressBook.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
ABAddressBook * book = [ABAddressBook sharedAddressBook];
NSArray * people = [book people];
int count = [people count];
int i;
for (i = 0; i < count; i++) {
ABPerson * person = [people objectAtIndex:i];
NSString * firstName = [person valueForProperty:@"First"];
NSString * lastName = [person valueForProperty:@"Last"];
printf("%s %s\n",
[lastName UTF8String],
[firstName UTF8String]);
}
[pool release];
return 0;
}
Xavier
On 03/05/2006, at 3:04 AM, Brad Bumgarner wrote:
It can be very difficult to learn a language on your own. I was/am
hoping that someone here can help me learn how to write obj-c code.
I have read the Address Book documentation the comes with Xcode and
I just can't figure how to put all the pieces to together. I know
what I want to do can be done, Mail.app does it all the time. If I
wasn't clear in the wording of my question, please let me know.
Thanks,
Brad Bumgarner, CTA
On May 1, 2006, at 12:02 PM, Brad Bumgarner wrote:
My name is Brad Bumgarner and I am new to Objective-C. I have been
using AppleScript since it was first introduced many (many)
"moons" ago. I have been using Project Builder / Xcode since OS X
10.2. I have recently decided to step up to using Objective-C so
that I may add features to my apps that I can't do (the way I'd
like to) in AppleScript Studio. The scary thing is Objective-C is
actually starting to make sense :-)
My question: How can I search for a name in Address Book? I want
to be able to search for first names, last names and both first/
last names. I want to be able to do this much like Mail.app does.
The code below (attached to a text field via AppleScript's "on
changed" handler) works until a space character is entered.
"theName" is passed from the applescript code and contains the
currently entered text from the text field as it is being entered.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40bigpond.net.au
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