Amazon.com Widgets Exercise 1 of Chapter 18
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 26, 2014, 02:50:04 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
Print
Author Topic: Exercise 1 of Chapter 18 (Read 1111 times)
MarkReid
Full Member
***
Posts: 173






on: May 07, 2010, 03: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?

Thanks
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







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

Mark,

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:  http://classroomm.com/objective-c/index.php?topic=2859.0

Cheers,

Steve Kochan
Logged
MarkReid
Full Member
***
Posts: 173






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

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

http://classroomm.com/objective-c/index.php?topic=3499.0

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.
Logged
Pages: [1] Go Up
Print
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 classroomM.com. All rights reserved.