We're in the final stages of completing the iOS 6 edition of the book right now, and I thought I'd take a moment to talk in general about the changes that we've seen in the iOS 6 SDK that have had the biggest impact on the book in terms of changes.
We've made lots of adjustments and improvements throughout the book, but there are a lot of recurring issues that fall into a few general categories which are worth mentioning. If you're using the iOS 5 edition of the book with the iOS 6 SDK, hopefully these points will help you sort out some common problems.
Removal of the viewDidUnload method
This UIViewController method is deprecated in iOS 6, and is no longer called. Most of the time, this change affects nothing in our projects, but I think there are a handful where we moved some code into a viewDidDisappear: or viewWillDisappear: method instead.
Restructuring of Xcode's "new file" assistant
Apple has removed some of the options there for creating a particular kind of subclass through an icon of its own. Instead, you just create a new Objective-C class and choose the appropriate superclass, and Xcode generates the appropriate template. For example, in the past there was an icon in the assistance specifically for creating a UIViewController subclass. Now, you instead just create an Objective-C class and choose UIViewController (or one of its subclasses) as your superclass.
File template changes
Apple changes its templates for various classes and projects now and then, and a huge part of our book-refresh process is going through all our examples and making sure that we're describing the current reality. Sometimes this means that Apple has removed an otherwise empty method implementation, so when we talk about adding some code to an empty method that now isn't there, you just need to add that method.
Automatic property synthesis
In the past, any @property
declaration in an @interface
had to be matched by something explicit in the @implementation
block. Most of the time we would have a simple @synthesize
to match, and occasionally we implement getters and setters in code. Starting in Xcode 4.4 and 4.5, there's another option: You can just leave out the @synthesize
entirely, and the compiler will create the getter and setter for you. At the same time, it will create an instance variable. The trick is that the new instance variable doesn't have the same name as the property; instead, it's the property name prepended with an underscore. So a property named "foo" is now backed by an instance variable named "_foo".
syntax has always allowed you to specify the name of the instance variable. In effect, the new behavior is that when implementing the implementation for a property "foo", just skipping the @synthesize
call is the same as doing this:
This new approach lets you create your classes with less repetition, and it's really a welcome change. Throughout the book, we've adopted this approach, and have removed @synthesize
pretty much everywhere.
The old "springs and struts" method of specifying how the layout of views should respond to changes in the size of a parent view has been replaced by a new system called Cocoa Auto Layout, which has been on the Mac for just over a year and has now made its way to iOS. Auto layout is a constraints-based system that can do everything that the old system could do, and a whole lot more. Most of the time, you can build your GUIs just the same as before and things will work pretty much as expected, with one serious caveat: the iPhone 5 throws a monkey wrench into the works. Before the iPhone 5, iOS developers could assume that the iPhone screen size was a known quantity (with the obvious exception of iPad, which is often solved by using different nibs/storyboards entirely), and could often assume there was no need to worry about GUI autosizing for an iPhone GUI, particularly if you disallowed rotation. Now however, the GUI you create in Interface Builder may well be loaded up on an iPhone whose screen size is taller or shorter than what you've built for. Depending on how the constraints in your GUI are configured, you may have some weird things happening in your GUI.
This is obviously something that is as new to us as to anyone else, since we had no confirmed info about the iPhone 5 until it was publicly revealed. On our final pass through the new book, we are taking extra care to look at our examples and see which need adjusting. It's hard to give concise, general advice about this, but if you're interested in this topic, you should take a look at Apple's Cocoa Auto Layout
guide for starters.
I hope this helps! Let me know if you have any questions about any of this.