Best practice for copying private instance vars with NSCopying

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2010-04-02T15:10:41Z Indexed on 2010/04/02 15:13 UTC
Read the original article Hit count: 335

I might be missing something obvious here, but I'm implementing NSCopying on one of my objects. That object has private instance variables that are not exposed via getters, as they shouldn't be used outside the object.

In my implementation of copyWithZone:, I need alloc/init the new instance, but also set up its state to match the current instance. I can obviously access current private state from inside copyWithZone:, but I can't set it into the new object, because there are no accessors for that state.

Is there a standard way around this while still keeping data privacy intact?

Thanks.

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about nscopying