views:

87

answers:

2

How do I take a NSObject that I have set all the attributes of and then copy that into another block of memory that an array can use so I can re use the original one?

+2  A: 

In short, you don't.

If you want to put the object in an array and then create a new object, do exactly that; addObject: to the array and alloc/init a new one.

If you are asking how you copy an object into, say, a random malloc() block somewhere -- say, in the middle of an array -- then that is a very different issue. It can technically be done, but basically no one does so as the frameworks and runtime aren't designed for that.

Without knowing more about your specific needs, it is impossible to go into more detail.

bbum
Here is a thread that I started that tc helped me out with but didnt help me all the way: http://stackoverflow.com/questions/3697072/well-using-nsxmlparser-the-values-inside-an-array-are-all-set-to-the-last-entry
pki
OK -- I see what your real question is.
bbum
I figured it all out now, but now I am leaking a date object.
pki
A: 

Making a copy of an object is done by sending it the copy message. This only works on instances of classes that implement the NSCopying protocol.

Read Implementing Copy for a good overview. Then read Implementing NSCopying Considered Harmful for some more background info.

St3fan
That doesn't answer the question; he wants to byte-copy the object into an array and then re-use the original.
bbum