Beginning iPhone Development with Swift

Exploring the iOS SDK

By David Mark , Jack Nutting , Kim Topley , Fredrik Olsson , Jeff LaMarche

  • eBook Price: $31.99 $19.99
  • Print Book Price: $44.99

Beginning iPhone Development with Swift Cover Image

  • Alpha Books are:
  • - Pre-release
  • - Unedited and incomplete
  • - Available only as PDFs until published
The team that brought you the bestselling Beginning iPhone Development, the book that taught the world to program on the iPhone, has been transformed to deliver the same excellent introduction to iPhone and iOS programming using Swift. Beginning iPhone Development with Swift introduces you to Swift in this definitive guide for iOS 8 and its SDK, as well as Xcode 6. (Source code now updated to reflect Xcode 6.3.1 and Swift 1.2!)

Full Description

  • Add to Wishlist
  • ISBN13: 978-1-484204-10-8
  • 828 Pages
  • User Level: Beginner to Intermediate
  • Publishing November 19, 2014, but available now as part of the
    Alpha Program
  • Available eBook Formats: EPUB, MOBI, PDF

Related Titles

  • Swift Game Programming for Absolute Beginners
  • Swift OS X Programming for Absolute Beginners
  • Get Fit with Apple Watch
  • Apple Watch for Developers
Full Description

The team that brought you the bestselling Beginning iPhone Development, the book that taught the world how to program on the iPhone, is back again for Beginning iPhone Development with Swift. This definitive guide to the Swift programming language and the iOS 8 SDK, and the source code has been updated to reflect Xcode 6.3.1 and Swift 1.2.

There’s coverage of brand-new technologies, including Swift playgrounds, as well as significant updates to existing material. You'll have everything you need to create your very own apps for the latest iOS devices. Every single sample app in the book has been rebuilt from scratch using the latest Xcode and the latest 64-bit iOS 8-specific project templates, and designed to take advantage of the latest Xcode features.

Assuming little or no working knowledge of the new Swift programming language, and written in a friendly, easy-to-follow style, this book offers a complete soup-to-nuts course in iPhone, iPad, and iPod touch programming. The book starts with the basics, walking through the process of downloading and installing Xcode and the iOS 8 SDK, and then guides you though the creation of your first simple application.

From there, you’ll learn how to integrate all the interface elements iOS users have come to know and love, such as buttons, switches, pickers, toolbars, and sliders. You’ll master a variety of design patterns, from the simplest single view to complex hierarchical drill-downs. The art of table building will be demystified, and you’ll learn how to save your data using the iPhone file system. You’ll also learn how to save and retrieve your data using a variety of persistence techniques, including Core Data and SQLite. And there’s much more!

What you’ll learn

  • Everything you need to know to develop your own bestselling iPhone and iPad apps
  • Utilizing Swift playgrounds
  • Best practices for optimizing your code and delivering great user experiences
  • What data persistence is, and why it’s important
  • Get started with building cool, crisp user interfaces
  • How to display data in Table Views
  • How to draw to the screen using Core Graphics
  • How to use iOS sensor capabilities to map your world
  • How to get your app to work with iCloud and more

Who this book is for

This book is for aspiring iPhone app developers, new to the Apple Swift programming language and/or the iOS SDK.

Table of Contents

Table of Contents

1. Welcome to the Swift Jungle

2. Appeasing the Tiki Gods

3. Handling Basic Interaction

4. More User Interface Fun

5. Rotation and Adaptive Layout

6. Multiview Applications

7. Tab Bars and Pickers

8. Introduction to Table Views

9. Navigation Controllers and Table Views

10. Collection Views

11. iPad Considerations

12. Application Settings and User Defaults

13. Basic Data Persistence

14. Hey! You! Get onto iCloud!

15. Grand Central Dispatch, Background Processing, and You

16. Core Graphics: Drawing with Quartz

17. Getting Started with Sprite Kit

18. Taps, Touches, and Gestures

19. Where Am I? Finding Your Way with Core Location and Map Kit

20. Whee! Gyro and Accelerometer!

21. The Camera and Photo Library

22. Application Localization

23. Appendix: A Swift Introduction to Swift

Source Code/Downloads

Downloads are available to accompany this book.

Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.

Errata

Please Login to submit errata.

On page 1-761:
Beginning iPhone Development with Swift – 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.

Author Comment:
Chapter 6 – Multiview Applications
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 – Introduction 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”.
Page 258: Replace “cell!.imageView.highlightedImage” with “cell!.imageView?.highlightedImage”.
Page 258: Replace “cell!.textLabel.text” with “cell!.textLabel?.text”
Page 260: Replace “cell!.textLabel.text” with “cell!.textLabel?.text”
Page 266: Replace “cell!.textLabel.text” with “cell!.textLabel?.text”
Page 266: Replace “cell!.textLabel.font” with “cell!.textLabel?.font”.
Page 273: Replace “as NameAndColorCell” with “as! NameAndColorCell”
Page 282: Replace “nameDict as [String: [String]]” with “nameDict as! [String: [String]]”
Page 282: Replace “sorted(namesDict!.allKeys as [String])” with “sorted(namesDict!.allKeys as! [String])”
Page 283: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 283: Replace “cell.textLabel.text” with “cell.textLabel?.text”.
Page 291: Replace “countElements(name)” with “count(name)”
Page 292: Replace “countElements(name)” with “count(name)”
Page 293: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 293: Replace “cell.textLabel.text” with “cell.textLabel?.text”.

Chapter 9 - Navigation Controllers and Table Views
Page 312: Replace “as [String]” with “as! [String]”
Page 313: Replace “as [String]” with “as! [String]”
Page 314: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 314: Replace “cell.textLabel.font” with “cell.textLabel?.font”
Page 314: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 314: Replace “cell.textLabel.text” with “cell.textLabel?.text”
Page 314: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 314: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 317: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 317: Replace “cell.textLabel.font” with “cell.textLabel?.font”
Page 317: Replace “cell.textLabel.text” with “cell.textLabel?.text”
Page 320: Replace “sender as UITableViewCell” with “sender as! UITableViewCell”
Page 320: Replace “as FontListViewController” with “as! FontListViewController”
Page 320: Replace “as [String]” with “as! [String]”
Page 321: Replace “sender as UITableViewCell” with “sender as! UITableViewCell”
Page 322: Replace “cell.textLabel.font” with “cell.textLabel?.font”
Page 322: Replace “cell.textLabel.text” with “cell.textLabel?.text”
Page 322: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 322: Replace “as FontSizesViewController” with “as! FontSizesViewController”
Page 322: Replace “as FontInfoViewController” with “as! FontInfoViewController”
Page 326: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 327: Replace “as FontSizesViewController” with “as! FontSizesViewController”
Page 327: Replace “as FontInfoViewController” with “as! FontInfoViewController”

Chapter 10 – Collection View

Page 341: Replace “collectionView. “ with “collectionView!.” In three places.
Page 342: Replace “as ContentCell” with “as! ContentCell”
Page 345: Replace “collectionView.” with “collectionView!”.
Page 345: Replace “as UICollectionViewFlowLayout” with “as! UICollectionViewFlowLayout”
Page 347: Replace “collectionView.” with “collectionView!” in the first line of the page.
Page 347: Replace “as HeaderCell” with “as! HeaderCell”
Chapter 11 – Using Split Views and Popovers

Page 356: Replace “as UISplitViewController” with “as! UISplitViewController”
Page 356: Replace “as UINavigationController” with “as! UINavigationController”
Page 357: Replace “as UISplitViewController” with “as! UISplitViewController”
Page 357: Replace “as UINavigationController” with “as! UINavigationController”
Page 363: Replace “segue.destinationViewController as” with “segue.destinationViewController as!”
Page 363: Replace “as DetailViewController” with “as! DetailViewController”
Page 365: Replace “as [NSDictionary] as [[String: String]]” with “as [NSDictionary] as [[String: String]]” (note that are two instances of ‘as!’)
Page 365: Replace “as [NSDictionary] as [[String: String]]” with “as [NSDictionary] as [[String: String]]” (note that are two instances of ‘as!’)
Page 366: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 366: Replace “cell.textLabel.text” with “cell.textLabel?.text” twice (the first is in crossed-out code).
Page 367: Replace “as UINavigationController” with “as! UINavigationController” and, in the same line, “as DetailViewController” with “as! DetailViewController”
Page 368: Replace “as [String: String]” with “as! [String: String]”
Page 373: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 373: Replace “cell.textLabel.text” with “cell.textLabel?.text”.
Page 383: Replace “as UNavigationController” with “as! UINavigationController”.
Page 383: Replace “as UISplitViewController” with “as! UISplitViewController”.
Page 383: Replace “as UIViewController” with “as! UIViewController”
Page 385: Replace “as UINavigationController” with “as! UINavigationController”
Page 385: Replace “as UISplitViewController” with “as! UISplitViewController”
Page 385: Replace “as UINavigationController” with “as! UINavigationController”
Page 386: Replace “as UINavigationController” with “as! UINavigationController”
Page 386: Replace “as UISplitViewController” with “as! UISplitViewController”
Page 386: Replace “as UINavigationController” with “as! UINavigationController”

Chapter 13 – Basic Data Persistence

Page 436: Replace “as NSString” with “as! NSString”
Page 436: Replace “as [String]” with “as! [String]”
Page 437: Replace “as NSArray” with “as! NSArray”
Page 437: Replace “as [String]” with “as! [String]”
Page 438: Replace “as NSArray” with “as! NSArray”
Page 440: Replace “as String” with “as! String”
Page 441: Replace “as String” with “as! String”
Page 441: Replace “as MyObject” with “as? MyObject”
Page 445: Replace “as FourLines” with “as! FourLines”
Page 445: Replace “as [String]” with “as! [String]”
Page 445: Replace “as NSString” with “as! NSString”
Page 453: Replace “as NSString” with “as! NSString”
Page 468: Replace “as AppDelegate” with “as! AppDelegate”
Page 468: Replace “as String” with “as! String”
Page 468: Replace “as AppDelegate” with “as! AppDelegate”
Page 469: Replace “as NSManagedObject” with “as! NSManagedObject”
Page 469: Replace “as NSManagedObject” with “as! NSManagedObject”

Chapter 14 – Documents and iCloud

Throughout this chapter, the type Byte should be replaced with UInt8. The type alias for Byte was removed in Swift 1.2. Using UInt8 is, in any case, clearer.

The type of UIDocument.undoManager has changed from NSUndoManager? to NSUndoManager:

Page 477: Replace “as NSData” with “as! NSData”
Page 479: Replace “as [NSURL] with “as! [NSURL]”
Page 479: Replace “URLByAppendingPathComponent(fileName)” with URLByAppendingPathComponent(filename as String)”
Page 479: Replace “as [String] with “as! [String]”
Page 479: Replace “as NSDate with “as! NSDate”
Page 480: Replace “as UITableViewCell” with “as! UITableViewCell”
Page 480: Replace “cell.textLabel.” with “cell.textLabel!.”
Page 481: Replace “import UIKIt” with “import UIKit”
Page 481: Replace “as UITextField” with “as! UITextField”
Page 484: Replace “as UINavigationController” with “as! UINavigationController”
Page 484: Replace “as DetailViewController” with “as! DetailViewController”
Page 491: Replace “as UITouch” with “as! UITouch”
Page 492: Replace “document.undoManager?” with “document.undoManager” in two places.
Page 492: Replace “touches: NSSet” with “touches: Set<NSObject>” in two places.
Page 495: Replace “as TinyPixDocument” with “as! TinyPixDocument”
Page 501: Replace “as NSMetaDataItem” with “as! NSMetaDataItem” in two places
Page 502: Replace “as NSDate” with “as! NSDate” in two places
Page 502: Replace “as [NSMetaDataItem]” with “as! [NSMetaDataItem]”
Page 502: Replace “url.lastPathComponent” with “url.lastPathComponent!”
Page 502: Replace “as NSURL” with “as! NSURL”

Chapter 15 – Grand Central Dispatch, Background Processing, And You

Page 509: Replace “countElements” with “count”

Chapter 16 – Drawing with Core Graphics
Page 552: Replace “NSSet” with “Set<NSObject>”
Page 552: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 553: Replace “NSSet” with “Set<NSObject>”
Page 553: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 553: Replace “NSSet” with “Set<NSObject>”
Page 553: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 557: Replace “as QuartzFunView” with “as! QuartzFunView”
Page 558: Replace “as QuartzFunView” with “as! QuartzFunView”
Page 566: Replace “NSSet” with “Set<NSObject>”
Page 566: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 566: Replace “NSSet” with “Set<NSObject>”
Page 566: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 567: Replace “NSSet” with “Set<NSObject>”
Page 567: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”

Chapter 17 – Getting Started with Sprite Kit

Page 571: Replace “as SKView” with “as! SKView”
Page 576: Replace “NSSet” with “Set<NSObject>”
Page 576: Replace “for touch: AnyObject in touches” with “for touch in (touches as! Set<UITouch>)”
Page 578: Replace “as SKView” with “as! SKView”
Page 583: Replace “touches: NSSet” with “touches: Set<NSObject>”
Page 583: Replace “for touch: AnyObject in touches” with “for touch in (touches as! Set<UITouch>)”
Page 591: Replace “touches: NSSet” with “touches: Set<NSObject>”
Page 591: Replace “for touch: AnyObject in touches” with “for touch in (touches as! Set<UITouch>)”
Page 592: Replace “as [BulletNode] with “as! [BulletNode]”
Page 595: Replace “as [EnemyNode] with “as! [EnemyNode]”

Page 598: Replace “SKPhysicsContact!” with “SKPhysicsContact”
Page 601: Replace “as SKLabelNode” with “as! SKLabelNode”
Page 605: Replace “as SKEmitterNode” with “as! SKEmitterNode”
Page 606: Replace “as SKEmitterNode” with “as! SKEmitterNode”
Page 607: Replace “as SKEmitterNode” with “as! SKEmitterNode”
Page 610: Replace “touches: NSSet” with “touches: Set<NSObject>”
Page 614: Replace “as SKLabelNode” with “as! SKLabelNode”
Page 615: Replace “i * sectionWidth” with “UInt32(i * sectionWidth)”

Chapter 18: Taps, Touches, And Gestures

Page 621: Replace “touches: NSSet” with “touches: Set<NSObject>”
Page 621: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 621: Replace “passed an NSSet” with “passed a Set”
Page 621: Replace “The NSSet passed” with “The Set passed”
Page 621: Replace “the anyObject() method of NSSet” with “the first property of Set”
Page 625: Replace “touches:NSSet!” with “touches: Set<NSObject>!”
Page 625: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 625: Replace “touches: NSSet” with “touches: Set<NSObject>” in four places
Page 628: Replace “touches: NSSet” with “touches: Set<NSObject>”
Page 628: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 628: Replace “touches: NSSet” with “touches: Set<NSObject>”
Page 628: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 639: Replace “UIGestureRecognizer!” with “UIGestureRecognizer” in two places
Page 641: Replace “UIGestureRecognizer!” with “UIGestureRecognizer” in two places
Page 645: Replace “touches: NSSet” with “touches: Set<NSObject>”
Page 645: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”
Page 645: Replace “touches: NSSet” with “touches: Set<NSObject>”
Page 645: Replace “touches.anyObject() as UITouch” with “touches.first as! UITouch”

Chapter 19: Where Am I? Finding Your Way with Core Location and Map Kit
Page 660: Replace “case .Authorized” with “case .AuthorizedAlways”
Page 661: Replace “as [CLLocation]” with “as! [CLLocation]”
Page 665: Replace “case .Authorized” with “case .AuthorizedAlways”

Chapter 20: Whee! Gyro and Accelerometer!
Page 687: Replace “touches: NSSet” with “touches: Set<NSObject>”
Page 689: Replace “as BallView” with “as! BallView”

Chapter 21: The Camera and Photo Library

Page 700: Replace “UIImagePickerController!” with “UIImagePickerController”
Page 700: Replace “[NSObject: AnyObject]!” with “[NSObject: AnyObject]”
Page 709: Replace “UIImagePickerController!” with “UIImagePickerController”
Page 709: Replace “[NSObject: AnyObject]!” with “[NSObject: AnyObject]”
Page 709: Replace “as? NSString” with “as? String”
Page 709: Replace “UIImagePickerController!” with “UIImagePickerController”

Chapter 22: Application Localization

Page 717: Replace “as [String]” with “as! [String]”

Appendix A: A Swift Introduction to Swift

Page 748: Replace “the function countElements()” with “the function count()”
Page 748: Replace “countElements(s3)” with “count(s3)”
Page 748: Replace “The countElements() function” with “The count() function”
Page 757: Replace “d as [String: String] with “d as! [String: String]”
Page 761: Replace “d as [Int: String] with “d as! [Int: String]”
Page 761: Replace “d[1] as String?” with “d[1] as! String?”
Page 761: Replace “d as [Int: String] with “d as! [Int: String]”



Best-Sellers

    1. Beginning iPhone Development with Swift

      $31.99

      View Details

    2. Pro Design Patterns in Swift

      $34.99

      View Details

    3. More iPhone Development with Swift

      $31.99

      View Details

    4. Beginning Xcode: Swift Edition

      $27.99

      View Details