• 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
Copying ABPerson (problem with MultiValue fields)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Copying ABPerson (problem with MultiValue fields)


  • Subject: Copying ABPerson (problem with MultiValue fields)
  • From: Brian Popp <email@hidden>
  • Date: Thu, 21 Jul 2005 23:52:59 -0500

I'm a newbie Cocoa developer working on a project for a friend of mine. I've done a lot of C++ and C, but Objective C is still pretty awkward for me. Basically what I'm trying to do is take a group from my address book, iterate through each record, create a copy of it, and then make a slight change to some of the fields of the copy. It seemed to be working ok, but then I realized that for some reason, the address field of the original record was getting blown away. A few seconds after the App runs, all the original records in my address book lose their address values (the copy has the correctly copied address, however).

I think it has something to do with the way I'm assigning the address property (if I comment it out, the address remains intact), but I don't understand why. Here's a section of the code:

    NSArray *peopleArray = [group members];
    for ( i=0; i<[peopleArray count]; i++ )
    {
        currentPerson = [peopleArray objectAtIndex:i];
        newPerson = [[[ABPerson alloc] init] autorelease];

// Copy the address
ABMutableMultiValue *anAddressList = [[currentPerson valueForProperty:kABAddressProperty] mutableCopy];
[newPerson setValue:anAddressList forProperty:kABAddressProperty];


id title = [currentPerson valueForProperty:kABTitleProperty];
id firstName = [currentPerson valueForProperty:kABFirstNameProperty];
id lastName = [currentPerson valueForProperty:kABLastNameProperty];
...


        // Add the person to the address book.
        [book addRecord:newPerson];

        // Release any allocated memory.
        [newPerson release];

        }
    // Save everything back to the address book
    if ( [book hasUnsavedChanges] ) [book save];


Does this look correct? Anyone see any glaring problems? Thanks in advance for any suggestions.
_______________________________________________
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
  • Follow-Ups:
    • Re: Copying ABPerson (problem with MultiValue fields)
      • From: Andreas Mayer <email@hidden>
  • Prev by Date: Re: Strange issue when converting from hex to float
  • Next by Date: Re: NSURLConnection dependency on RunLoop (Sanity check)
  • Previous by thread: Re: NSDateFormatter on NSTextField
  • Next by thread: Re: Copying ABPerson (problem with MultiValue fields)
  • Index(es):
    • Date
    • Thread