Exercises
1. Implement a copy method for the AddressBook class according to the NSCopying protocol. Would it make sense to also implement a mutableCopy method? Why or why not? Also, think about what happens if someone uses the setter method for the book property in the AddressBook class. Who should own the address book that gets passed as the argument to the setter? How can you fix this?
2. Modify the Rectangle and XYPoint classes defined in Chapter 8 to conform to the <NSCopying> protocol. Add a copyWithZone: method to both classes. Make sure that the Rectangle copies its XYPoint member origin using the XYPoint’s copy method. Does it make sense to implement both mutable and immutable copies for these classes? Explain.
3. Create an NSDictionary ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access