• 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
even after the longish diatribes on copying....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

even after the longish diatribes on copying....


  • Subject: even after the longish diatribes on copying....
  • From: Theodore Petrosky <email@hidden>
  • Date: Mon, 14 Jun 2004 06:50:44 -0700 (PDT)

I apologize.. even after reading eveything I can on
copying objects, I just seem to miss the point. I have
a class that is a collection of NSStrings with setters
and getters..

in the header

NSString *fName;

- (NSString *)fName;
- (void)setFName:(NSString *)aFName;

@implementation Person
//
=======================================================
// - fName:
//
=======================================================
- (NSString *)fName { return fName; }

//
======================================================
// - setFName:
//
=======================================================
- (void)setFName:(NSString *)aFName
{
if (fName != aFName) {
[fName release];
fName = [aFName retain];
}
}

@end

so that in the Controller class I am creating a person

currentPerson = [[Person alloc] init];

what I want to do is...

duplicateOfPerson = [currentPerson copy];

I want a deep copy. I want to alter a variable in
currentPerson and then compare that variable to
duplicateOfPerson to see what was changed (if
anything).

What I get is a shallow copy. If I change something in
currentPerson, that change follows into
duplicateOfPerson.

I guess I could just create a method that allocs
another Person and then uses the setter methods to
populate the variables. But I thought I would use a
'copy'.

I have been reading all the docs but I just don't get
it.

Thanks for the help.

Ted





__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
_______________________________________________
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.


  • Follow-Ups:
    • Re: even after the longish diatribes on copying....
      • From: Marcel Weiher <email@hidden>
    • Re: even after the longish diatribes on copying....
      • From: Brent Gulanowski <email@hidden>
  • Prev by Date: Re: Button for switching mode/tools for NSToolbar
  • Next by Date: Re: receiving key equivalent events
  • Previous by thread: Re: Button for switching mode/tools for NSToolbar
  • Next by thread: Re: even after the longish diatribes on copying....
  • Index(es):
    • Date
    • Thread