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

Re: even after the longish diatribes on copying....


  • Subject: Re: even after the longish diatribes on copying....
  • From: Marcel Weiher <email@hidden>
  • Date: Mon, 14 Jun 2004 16:17:17 +0100

NSString *fName;

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

@implementation Person
- (NSString *)fName { return fName; }
- (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];

OK.

what I want to do is...

duplicateOfPerson = [currentPerson copy];

For that you need an implementation of a copyWithZone: method:

We need to see your implementation of -copy(WithZone:)in order to help you.

I want a deep copy.

Then implement that in your -copy method

What I get is a shallow copy.

I am surprised you are not getting a DNU, since you don't seem to be implementing -copy.

Maybe you are inheriting from a superclass that implements copy as retain?

I guess I could just create a method that allocs
another Person and then uses the setter methods to
populate the variables.

Well, that is probably exactly what you will end up doing in your copy method.

But I thought I would use a 'copy'.

?


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

Maybe you are missing the fact that -copy is something you have to implement?

Cheers,

Marcel
_______________________________________________
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: 
 >even after the longish diatribes on copying.... (From: Theodore Petrosky <email@hidden>)

  • Prev by Date: NSTextAttachment problems
  • Next by Date: Re: even after the longish diatribes on copying....
  • Previous by thread: Re: even after the longish diatribes on copying....
  • Next by thread: #define works, const short does not for Ctype array in class
  • Index(es):
    • Date
    • Thread