Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Workshop

Quiz

1. If you use an immutable collection, can you ever make a change to it?

2. Why can you create a set from an array but you cannot create an array from a set?

Quiz Answers

1. You can change it with one of the init methods if you have created it with alloc, but that is the extent of the modifications you can make.

2. Arrays are ordered, and sets are unordered. Converting an array (ordered) to an unordered set means ignoring a piece of data. Doing the reverse would require you to create the order. You can use the NSSet allObjects method to convert the set to an array and then use arrayWithArray to create an array, but allObjects presents the data in an undefined order (which is set behavior).

Activities

Create a collection with half a dozen objects in it. Use one of the immutable classes. Now write code to extract three of the objects into a new collection. To become even more familiar with collections, extract objects based on some characteristic. This helps you become familiar with additional methods of the collection classes.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint