18. Copying Objects
This chapter discusses some of the subtleties involved in copying objects. We will introduce the concept of shallow versus deep copying and how to make copies under the Foundation framework.
Chapter 8, “Inheritance,” discussed what happens when you assign one object to another with a simple assignment statement, such as
origin = pt;
In that example, origin
and pt
are both Point
objects, that we defined like this:
@interface Point: Object{ int x; int y;}; ...@end
You will recall that the effect of the assignment is to simply copy the address of the object pt
into origin
. At the end of the assignment operation, both variables point to the same location in memory. Making changes to the instance variables with a message ...
Get Programming in Objective-C now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.