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?
Creating a Custom ClassGo ahead an choose “Objective-C class” and hit Next. For the class name, enter “Person.” Make it a subclass of NSObject. NSObject is the base class for all objects in Apple's developer environment. It provides basic properties and functions for memory management and allocation.
Copy is useful when you do not want the value that you receive to get changed without you knowing. For example if you have a property that is an NSString and you rely on that string not changing once it is set then you need to use copy.
The root class of most Objective-C class hierarchies, from which subclasses inherit a basic interface to the runtime system and the ability to behave as Objective-C objects.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With