Chapter 4. Storing data in collections

 

This chapter covers

  • NSArray
  • NSDictionary
  • Storing nil and other special values in collections
  • Boxing and unboxing non-object-based data

Chapter 3 introduced the concept of object-oriented programming and demonstrated some of its advantages by using the services of the prebuilt NSString class, which provides common text manipulation and query-related functionality.

A large part of Foundation Kit is concentrated on the storage of data in collection data structures with names such as arrays, dictionaries, sets, and hashmaps. These data structures allow you to efficiently collect, group, sort, and filter data in a way that’s convenient for the application at hand. Discussing these commonly used classes is what this chapter is all about.

Let’s start by discussing how Foundation Kit improves upon a data structure you’re currently familiar with: a simple array.

4.1. Arrays

The Rental Manager application, as it currently stands, stores a list of rental property details in a C-style array called properties. Inherently, nothing’s wrong with this technique, but it has some limitations. For example, when you declare a C-style array, you create it with a fixed number of elements, and it’s not possible to add or remove additional elements from the array without recompiling the application. Your rental management business may become more successful and require the ability to add new properties to the list at runtime.

4.2. Dictionaries

 
 
 

4.3. Boxing

 
 
 

4.4. Making the Rental Manager application data driven

 
 
 
 

4.5. Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest