Programming iOS 7
Matt Neuburg
Beijing Cambridge Farnham Kln Sebastopol Tokyo
Preface
Aut lego vel scribo; doceo scrutorve sophian.
Sedulius Scottus
This book, now in its fourth edition, has grown in size to encompass the growth in its subject, until it can grow no more. The previous editions Programming iOS 4 (May 2011), Programming iOS 5 (March 2012), and Programming iOS 6 (March 2013) were approximately 800 pp., 950 pp., and 1150 pp. in length, respectively, not because I had more to say each time, but because Apple, as it added features to iOS 4 to make iOS 5, and to iOS 5 to make iOS 6, had given me more to describe.
Now iOS 7 has come along with even more new features, and drastic action was needed. Accordingly, the book has been ripped violently but neatly in two neatly, because there was already a perfectly natural place to do the ripping, namely right after the end of what used to be Part III (Chapter 13). There are now two books:
- A new book, iOS 7 Programming Fundamentals , comprising chapters 113 of the earlier books.
- This book, Programming iOS 7 , comprising chapters 1440 of the earlier books.
The truth is that this is a division I had wanted to make even before Programming iOS 4 was published indeed, before it was even conceived of. My original proposal to OReilly Media, back in early 2010, had been for a book to be called Fundamentals of Cocoa Programming , intended to cover very much the same material as iOS 7 Programming Fundamentals covers now. But the proposal was accepted only on condition that it be extended to cover much more of Cocoa Touch (iOS) programming; so I complied and set to work on this longer project, and later, despite my impassioned pleas in the autumn of 2010, I was unable to persuade the publisher to break up the lengthy manuscript into two: by that time, all the kings horses and all the kings men could no longer crack Humpty Dumpty apart.
The new situation, therefore, is just what I always wanted in the first place but not quite, because what I most desired was a single book in two volumes. My idea was that the books would have the same title, distinguished as Volume I and Volume II, with successive numbering of pages and chapters: if Volume I ended, say, with Chapter 13 and page 400, then Volume II would start with Chapter 14 and page 401. To this delightfully Victorian extreme, Im sorry to say, OReilly Media were implacably opposed.
Thus, Programming iOS 7 , though it starts with its own Chapter 1 and page 1, nevertheless still picks up exactly where iOS 7 Programming Fundamentals leaves off. They complement and supplement one another. Those who desire a complete grounding in the knowledge needed to begin writing iOS apps with a solid and rigorous understanding of what they are doing and where they are heading will, I hope, obtain both books. At the same time, the two-book architecture should, I believe, render the size and scope of each book individually more acceptable and attractive to more readers.
Those who feel that they know already all there is to know about C, Objective-C, Xcode, and the linguistic and architectural basis of the Cocoa framework, or who are content to pick up such underpinnings as they go along, need no longer (as some in the past have done) complain that the book is occupied with 13 preliminary chapters before the reader starts really writing any significant iOS code, because those 13 chapters have now been abstracted into a separate volume, iOS 7 Programming Fundamentals , and this book, Programming iOS 7 , now begins, like Homers Iliad , in the middle of the story, with the reader jumping with all four feet into views and view controllers, and with a knowledge of the language and the Xcode IDE already presupposed. And if such a reader subsequently changes his or her mind and decides that a thorough grounding in those underpinnings might in fact be desirable, iOS 7 Programming Fundamentals will still be available and awaiting study.
Moreover, the existence of iOS 7 Programming Fundamentals means that I, as author and teacher, can make the same assumption in this edition about you, as reader and student, that I made in previous editions namely, that you have a command of the material in that book. If you find yourself mystified by terminology or concepts used in this book, then it might be wise to stop reading it and take up iOS 7 Programming Fundamentals first! In it, I explain such things as:
- The Objective-C language, starting with C and building up to the object-oriented concepts and mechanics of classes and instances in Objective-C itself.
- Xcode, the world in which all iOS programming ultimately takes place, including what an Xcode project is and how it is transformed into an app, and how to work comfortably and nimbly with Xcode to consult the documentation and to write, navigate, and debug code, as well as how to bring your app through the subsequent stages of running on a device and submission to the App Store. There is also a very important chapter on nibs and the nib editor (Interface Builder), including outlets and actions as well as the mechanics of nib loading. (However, some additional important nib-related topics, such as autolayout constraints and storyboard segues, are discussed in this book.)
- The Cocoa Touch framework, which provides important foundational classes and adds linguistic and architectural devices such as categories, protocols, delegation, and notifications, as well as the pervasive responsibilities of memory management, plus keyvalue coding and keyvalue observing.
With those basics having been laid down in iOS 7 Programming Fundamentals , this book, Programming iOS 7 , assumes that you already know Objective-C and how to work with Xcode to edit code and nibs, make properties and outlets and actions, and so forth, and proceeds to explain the constituents of practical iOS app construction:
- describes views , the fundamental units of an iOS apps interface. Views are what the user can see and touch in an iOS app. To make something appear before the users eyes, you need a view. To let the user interact with your app, you need a view. This part of the book explains how views are created, arranged, drawn, layered, animated, and touched.
- starts by discussing view controllers . Perhaps the most remarkable and important feature of iOS programming, view controllers enable views to come and go coherently within the interface, thus allowing a single-windowed app running on what may be a tiny screen to contain multiple screens of material. This part of the book talks about all the ways in which view controllers can be manipulated in order to make their views appear. It also describes every kind of view provided by the Cocoa framework the built-in widgets with which youll construct an apps interface.
- surveys many of the secondary frameworks provided by iOS. These are clumps of code, sometimes with built-in interface, that are not part of your app by default, but are there for the asking if you need them, allowing you to work with such things as sound, video, user libraries, mail, maps, and the devices sensors.
- wraps up the book with some miscellaneous but important topics: files, networking, threading, and how to implement Undo and Redo.
- summarizes the most important lifetime event messages sent to your app delegate.