Re: AddressBook problems
Re: AddressBook problems
- Subject: Re: AddressBook problems
- From: Vince DeMarco <email@hidden>
- Date: Fri, 14 Feb 2003 22:04:20 -0800
On Friday, February 14, 2003, at 09:34 PM, Hasan Diwan wrote:
The code below generates a "*** Uncaught exception: <NSRangeException>
*** -[NSCFArray objectAtIndex:]: index (2147483647) beyond bounds
(1)"... And I can't see where the error is. Thanks in advance for the
help!
#import <AddressBook/AddressBook.h>
#import <Cocoa/Cocoa.h>
int main(int argc, char **argv) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *data = [[ABAddressBook sharedAddressBook] people];
NSEnumerator *i=[data objectEnumerator];
id rec;
while (rec = [i nextObject]) NSLog(@"%@\n", [[rec
valueForProperty:kABAddressProperty] valueAtIndex:[[rec
valueForProperty:kABAddressProperty]
indexForIdentifier:kABAddressStreetKey]]);
[pool release];
return 0;
}
the code is wrong.
you get a person the enumerator code is correct
NSArray *data;
NSEnumerator *enu;
ABPerson *rec;
ABMultiValue *value;
NSDictionary *address;
unsigned int i,count;
data = [[ABAddressBook sharedAddressBook] people];
enu = [data objectEnumerator];
while(rec = [enu nextObject]){
value = [rec valueForProperty:kABAddressProperty];
count = [value count];
for(i=0;i<count;i++){
NSLog(@"street is %@",[value objectForKey: kABAddressStreetKey]);
}
}
the identifier in a MultiValue is a key to allow you to have a pointer
to a particular value. For example if there are 4 values in the
Multivalue (home, work, etc...)
and the user deletes the first entry your pointer is still valid.
vince
_______________________________________________
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.