It was hard to tell if the cheers of joy or cries of fear were louder when Swift was announced, the next generation programming language to provide rapid development and more error free code than its predecessor Objective-C. There is nothing to fear. Grabbing the best from many different languages Swift makes for a completely new, faster and better programming experience which you will come to love.
Not as noticed in iOS8, but with as big an impact was size classes powered by auto layout. Size classes change the use of story boards, and present view controllers in new ways programmatically to make truly universal apps without extra code for each device.
In this book, you will learn to use auto layout, size classes and new Swift implementations for all the major types of view controllers including:
- Modal views
- Action Sheets
- Navigation Controllers
- Tab Bar Controllers
- Table Views
- Split Views
- Page views
- Collection Views
With plenty of color illustrations and code snippets, Swift Swift View Controllers will take you step by step through many easy demonstrations, teaching you the stuff you really need to know to implement any of these view controllers. The book will help you understand how to move data between all these view controllers with delegates, segues and more for an efficient and well-written app.
If you are an intermediate programmer getting into auto layout or Swift’s view controllers, or you just finished a beginning guide to Swift and want more, Swift Swift: UI View Controllers will be invaluable.
Downloading Source Code and Assets
NOTE: All the source code available below is for Swift 1.0. It is obsolete. If you want to work through converting it to Swift 3.0 I’d suggest watching the WWDC2016 presentation Swift API design guidelines. I will be updating the code as I finish the Xcode 8 version of the book. That process will begin in November 2016.
I’m paranoid about zip files from strangers and of sending too much information. It’s too easy to stick something not so good in something. I feel that keeping what you download from me as secure as possible is a good thing. I also know a lot of people who can’t figure out Github. So I get old-fashioned about this: I send only source code files when possible and keep my downloads small.
You will find downloads on the website for each chapter as a .zip file. There will be .swift files and one .storyboard file in each exercise. In a few cases there will be .png files which are graphics you need for the demo. For example, for section 2 of Chapter Two you will find the following files:
Open a new project as described in each of the sections. Once you have a blank project, send ViewController.swift and Main.storyboard to the garbage can. From the place you downloaded and unpacked the source code, drag the code into the new project’s navigator. You will get the following:
Complete asset and source code in one zip file:
Chapter 1 :Introduction
In chapter 1 I introduce what we will cover in the rest of the book, and how to read and use the code found throughout the book.
Chapter 2: MVC and Connections
In Chapter 2 I explain the Model View Controller programming pattern, a pattern so fundamental Xcode forces you to use it. I explain what MVC is, why to use it, and then using navigation controllers demonstrate how to communicate between view controllers using MVC. I then explain the most misunderstood but necessary programming pattern of all for iOS programming: delegation.
Section 1 : The Model View Controller Pattern
Section 2 : A Model View Controller Example
Section 3 : Using Segues
Section 4 : Protocols and Delegation
Section 5 : Property Observers
Chapter 3: Auto Layout and Size Classes
In Chapter 3 we’ll introduce size classes. As a prerequisite, we’ll introduce and use auto layout. We’ll work through a universal layout that displays differently on different devices on a single storyboard.
Section 1: Beginning Auto Layout
Section 2: Working with Auto Layout
Section 3: Starting with Size Classes
Section 4: Compact Size Classes
Section 5: Regular Class Sizes
Section 6: Fixing Conflicting Constraints
Chapter 4: Modal View Controllers
In Chapter 4, we discuss modal view controllers. We show how to present them from the storyboard, and then a xib. We discuss how size classes relate to their presentation, as well as transition styles. There are three special controllers that are now modal controllers in iOS8: popovers, alerts and action sheets. We complete the chapter discussing each of these.
Section 1: Presenting Modal Controllers
Section 2: Xibs and Modal Delegates
Section 3: Presenting Modals Universally
Section 4: Using Popovers
Section 5: Using Alerts and Action Sheets
Chapter 5: Embedded Controllers
In Chapter 5 we discuss two controllers that affect navigation: navigation controllers and tab bar controllers. As many topics about navigation controllers get covered in the fundamentals, we discuss some programmatic and customizing techniques for navigation controllers. The rest of the chapter covers setting up and sharing data in tab bar controllers.
Section 1: Navigation Controllers
Section 2: Tab Bar Controllers
Section 3: Coding Tab Bar Controllers
Section 4: Models and Tab Bar controllers
Chapter 6: Delegate Controllers
Some controllers use delegates and data sources for much of their operation. In Chapter 6 we cover how to use these controllers: table view controllers, the split view controller, the page view controller and the collection view controller. We discuss how to implement them, configure their appearance and how to use data with them.
Section 1: Table view Controllers
Section 2: Split View Controllers
Section 3: Page View Controllers
Section 4: Collection View Controllers