
Beginning iPhone Development with Swi – changes for Xcode
versions up to 6.3.
In Xcode 6.1.1, Apple changed the mapping from Objective-C to Swift of several
properties. As a result, some of the example code in the printed book no longer
compiles.
In Xcode 6.3, Apple made further changes to Swift. The changes that affect the
example source code are:
1. The “forced cast” operator ‘as’ must be replaced everywhere by ‘as!’ when
performing a downcast (for example, a cast from a base class such as
AnyObject to a subclass). You can still use ‘as’ when casting from a subclass
to a base class, or when casting from a Swift type to the corresponding
bridged Objective-C type (such as “let s = “Fred” as NSString”). Usages of the
‘as?’ operator are not affected.
2. The Swift library function countElements() was renamed to count().
3. A new collection type called “Set” has been added. Some APIs that had
arguments of type NSSet now expect arguments of type Set<NSObject>.
The source code archive on the book’s site has been updated. The changes to the
text are listed below.
Chapter 6 – Mul!view Applica!ons
Page 192: Replace “as BlueViewController” with “as! BlueViewController”.
Page 193: Replace “as BlueViewController” with “as! BlueViewController” in two
places.
Page 193: Replace “as YellowViewController” with “as! YellowViewController”.
Page 194: Replace “as YellowViewController” with “as! YellowViewController”.
Page 194: Replace “as BlueViewController” with “as! BlueViewController”
Page 200: Replace “as YellowViewController” with “as! YellowViewController”.
Page 201: Replace “as BlueViewController” with “as! BlueViewController”
Chapter 7 – Tab Bars and Pickers
Page 233: Replace “as [String: [String]]” with “as! [String: [String]]”
Page 235: Replace “as [String: [String]]” with “as! [String: [String]]”
Chapter 8 – Introduc!on to Table Views
Page 254: Replace “cell!.textLabel.text” with “cell!.textLabel?.text”
Page 256: Replace “cell!.textLabel.text” with “cell!.textLabel?.text”
Page 258: Replace “cell!.imageView.image” with “cell!.imageView?.image”.