Widgets Exercise 1 of Chapter 18
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 05, 2015, 06:47:13 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Chapter Study
| | |-+ Chapter 18 - Copying Objects
| | | |-+ Exercise 1 of Chapter 18
Pages: [1] Go Down
Author Topic: Exercise 1 of Chapter 18 (Read 1276 times)
Full Member
Posts: 173

on: May 07, 2010, 04:10:39 PM

So far I've got an address book with four cards ok. I can also copy the AddressBook name without any problems. The question I have however is when it comes to the array should I be looking to make a mutable copy? Am I really just looking to create a copy of the address book as it exists or create a new address book that can have items added to it and removed from it?

As this section of the book only covers shallow copying besides writing my own method am I right that all I'm supposed to be doing it creating a shallow copy of the address book?

Hero Member
Posts: 3114

Reply #1 on: May 07, 2010, 05:07:21 PM


Well, as the exercise asks, does it make sense to have a mutable copy method for your AddressBook class?  You might want to make an immutable copy of your AddressBook, say for a backup.   A mutable copy would be useful if you wanted to make changes to it.   As you've noted, these will typically be shallow copies if you follow the way the Foundation copy methods are implemented.  However, as the designer of the class, you get to decide how you want to implement your copies.

Here's a good discussion you may want to look at:


Steve Kochan
Full Member
Posts: 173

Reply #2 on: May 08, 2010, 03:09:14 PM

Thanks Steve, posted my attempt at it here. Would appreciate any feedback on it you may have. -

Still not sure I understand it after coding it but I think copying objects when trying to do a deep copy takes more practice. Although from what I read archiving to memory and putting it back into another object using NSData seems more the way to go, is that common practice for a deep copy?

Thanks again.
Pages: [1] Go Up
Jump to:

Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 All rights reserved.