Book Image

Swift Essentials - Second Edition

By : Alex Blewitt
Book Image

Swift Essentials - Second Edition

By: Alex Blewitt

Overview of this book

Swift was considered one of the biggest innovations last year, and certainly with Swift 2 announced at WWDC in 2015, this segment of the developer space will continue to be hot and dominating. This is a fast-paced guide to provide an overview of Swift programming and then walks you through in detail how to write iOS applications. Progress through chapters on custom views, networking, parsing and build a complete application as a Git repository, all by using Swift as the core language
Table of Contents (17 chapters)
Swift Essentials Second Edition
About the Author
About the Reviewer

Accessing repositories from view controllers

In the MasterViewController (created from the Master Detail template or a new subclass of a UITableViewController), define an instance variable, AppDelegate, which is assigned in the viewDidLoad method:

class MasterViewController:UITableViewController {
  var app:AppDelegate!
  override func viewDidLoad() {
    app = UIApplication.sharedApplication().delegate
     as? AppDelegate

The table view controller provides data in a number of sections and rows. The numberOfSections method will return the number of users with the section title being the username (indexed by the users list):

override func numberOfSectionsInTableView(tableView: UITableView)
 -> Int {
  return app.users.count
override func tableView(tableView: UITableView,
 titleForHeaderInSection section: Int) -> String? {
  return app.users[section]

The numberOfRowsInSection function is called to determine how many rows are present in each section. If the number is not...