01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

54 CHAPTER 2 Data types, variables, and constants<br />

The tableView:numberOfRowsInSection: implementation isn’t notable. It returns<br />

the number of items present in the properties array (5). It makes use of a C preprocessor<br />

macro defined in listing 2.4 to determine this number, but more about that later.<br />

The tableView:cellForRowAtIndexPath: implementation has a couple of changes.<br />

The first is a change in table view cell styles. You’re now requesting UITableViewCell-<br />

StyleSubtitle, which provides an iPod application–style cell with two horizontal<br />

lines of text: a main one that’s black followed by a gray line designed to show additional<br />

details.<br />

In tableView:cellForRowAtIndexPath: you’re provided with the index of the row<br />

the UITableView wants data for via the indexPath.row property. You can use this<br />

expression to index into the properties array to access the details, such as the<br />

address, of the associated property. Likewise, you can format a similar string detailing<br />

the rental price of the property to two decimal places for use as the details line.<br />

Build and run the application (Cmd-R), and you should be rewarded with a much<br />

better list of rental properties. Your first practical version of the Rental Manager application<br />

is completed!<br />

2.6 Summary<br />

All software applications are ultimately about data and how to interpret, process, and<br />

present it to the user. Even games are required to store maps, enemy positions, and<br />

scoring information, for example. It’s important to have a strong grasp of how to represent<br />

and store data in your applications.<br />

In this chapter, you met some of the most basic data types available to <strong>Objective</strong>-C<br />

developers, including int, float, char, and bool. We also highlighted some of the<br />

potential issues these data types could throw up, such as the inability of floating-point<br />

numbers to accurately represent all values in their stated ranges.<br />

As programs start to develop and grow in complexity, managing a large number of<br />

individual variables becomes untenable, so we investigated a number of <strong>Objective</strong>-C<br />

features such as enumeration, structures, and arrays that allow you to group multiple<br />

fields and constants.<br />

In chapter 3, we complete our coverage of <strong>Objective</strong>-C data types by discussing the<br />

concept of objects. Objects are another form of data type, but clearly, because<br />

<strong>Objective</strong>-C begins with the word object, understanding them is fairly critical to the success<br />

use of <strong>Objective</strong>-C.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!