Re: Copying ABPerson (problem with MultiValue fields)
Re: Copying ABPerson (problem with MultiValue fields)
- Subject: Re: Copying ABPerson (problem with MultiValue fields)
- From: Brian Popp <email@hidden>
- Date: Sat, 23 Jul 2005 12:57:31 -0500
That's good to know, but apparently not my problem. I've tried it
several different ways: with the release, without the release,
without the autorelease (and a matching release), etc. I really don't
understand why my original record's address is getting clobbered
because I'm not making any changes to it? Basically I'm reading
various values from the original record and then setting the
corresponding values in the copy. It's bizarre.
Thanks for the response. Anyone see anything else wrong with my code?
One thing I haven't been able to confirm, but my friend used this app
quite a bit pre-tiger and we never noticed it happening (seems like
we would). I'm starting to wonder if it's either a bug or a change to
the API in Tiger.
On Jul 22, 2005, at 7:47 AM, Andreas Mayer wrote:
You are releasing newPerson twice:
Am 22.07.2005 um 06:52 Uhr schrieb Brian Popp:
newPerson = [[[ABPerson alloc] init] autorelease];
[newPerson release];
Andreas
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