Structures
The Objective-C language provides another tool besides arrays for grouping elements. You also can use structures, which form the basis for the discussions in this section.
Suppose you wanted to store a date—say, 7/18/11—inside a program, perhaps to be used for the heading of some program output or even for computational purposes. A natural method for storing the date is to simply assign the month to an integer variable called month, the day to an integer variable day, and the year to an integer variable year. So, the statements
int month = 7, day = 18, year = 2011;
would work just fine. This is a totally acceptable approach. But what if your program also needed to store several dates? It would be much better to somehow group these ...
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