• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AddressBook problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >AddressBook problems (From: Hasan Diwan <email@hidden>)

  • Prev by Date: Instantiate NSCell in IB?
  • Next by Date: AddressBook -- more issues
  • Previous by thread: AddressBook problems
  • Next by thread: Instantiate NSCell in IB?
  • Index(es):
    • Date
    • Thread