Re: NSCopying is manual labor
Re: NSCopying is manual labor
- Subject: Re: NSCopying is manual labor
- From: Charilaos Skiadas <email@hidden>
- Date: Wed, 30 Mar 2005 18:32:36 -0600
On Mar 30, 2005, at 6:11 PM, Adam wrote:
Now I also have a NSMutableArray of objects that I created. If I call
mutableCopy on the array will it copy the contained objects as well if
they have copyWithZone methods?
Not sure, but it would not be too hard to write a small program to
test, would it? In fact:
http://www.cocoabuilder.com/archive/message/cocoa/2000/10/30/32037
Adam
On Mar 30, 2005, at 8:27 AM, Ondra Cada wrote:
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:
email@hidden
This email sent to email@hidden
Haris
_______________________________________________
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