Re: Ignoring an empty field in the address book (bug?)
Re: Ignoring an empty field in the address book (bug?)
- Subject: Re: Ignoring an empty field in the address book (bug?)
- From: Simon Stapleton <email@hidden>
- Date: Mon, 6 Jan 2003 16:30:21 +0100
Date: Sun, 05 Jan 2003 21:24:31 -0800
Subject: Re: Ignoring an empty field in the address book (bug?)
From: Ben Mackin <email@hidden>
To: <email@hidden>
Well, it looks like most of us are stumped. From the bit of offlist
help I
got, this one onlist message, and some more messing around on my part,
I
have come to the conclusion it is not possible to check if a property
exists
for a given ABPerson (for example checking if the given person has a
company
associated with them or not).
So what I wonder is how others get around this. How do you list all the
names in the address book in your programs for example? My address
book has
some entries with no last names, and my code just craps out at that
point
(once it tries to grab the last name on a record that doesn't have
one, it
quits out). And I can't check if the record has a last name or not,
because
it just raises an exception.
Well, if it's raising an exception, it IS possible to check if a
property exists. It may not look pretty, but this should do it:
id thePerson = [peopleFound objectAtIndex:i];
NS_DURING
NSLog (@"Value for property is %@", [thePerson
valueForProperty:kABLastNameProperty]);
NS_HANDLER
NSLog (@"No last name");
NS_ENDHANDLER
Of course, that doesn't allow for other exceptions to be raised (more
checking required in the handler) but it should be a start.
You would think it should just return n empty
string...
Well, you might. On the other hand, an empty string is very different
to no string at all. I suspect it's the way it is because it was
designed to be that way.
Try changing that if statement to:
if ([[peopleFound objectAtIndex:i]
valueForProperty:kABLastNameProperty])
Unfortunatly same thing. It stops and says:
[NSCFString stringByAppendingString:]: nil string (or other) argument
If you consider this a bug, I'd suggest running your test code through
the debugger with a break on [NSException raise], then providing your
code, the stack backtrace, etc to apple through bugreporter.
Hope that helps some
Simon
--
PGP Key Id : 0x50D0698D
--
If the answer isn't obvious, the question is a distraction. Go find an
easier question.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.