Re: NSCopying is manual labor
Re: NSCopying is manual labor
- Subject: Re: NSCopying is manual labor
- From: Ondra Cada <email@hidden>
- Date: Wed, 30 Mar 2005 15:27:15 +0200
Adam,
On 30.3.2005, at 12:54, Adam wrote:
I am just beginning to read about NSCopying, but from what I
understand I have to implement a copyWithZone method in my model class
, init a new object, and by hand copy all 20 instance variables from
the current object into the new object. Then since two of my instance
variables are themselves model objects I need to repeat this process
over again for each class. This is a lot of work. Is there something I
am missing that can just copy an entire object and its contents in its
current state, or am I on the right track to do it manually like this?
These things cannot reasonably be automated: the library can't know
which properties are to be copied and which (being transient, or
computed, or optional, or whatever) are not. You can add your own
abstraction layer which would define the properties to be copied of
course, and then automate it; I did it many times and therefore am
slightly doubtful whether it is worth the effort, but in some cases it
well might be.
That all said, check KVC, namely dictionaryWithValuesForKeys: and
setValuesForKeysWithDictionary:.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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