Creating helpers
Before starting with the program, let's add some code that will help us through the app development process. Add a new file called Helpers.swift
and add a helper function to execute the code in the main queue.
import Foundation func M(block: dispatch_block_t){ dispatch_async(dispatch_get_main_queue(), block) }
Note
If you prefer, you can implement the M
function in different ways. Some people prefer using NSOperation
and some of them prefer using alternative frameworks like Async
(https://github.com/duemunk/Async). It is up to you to choose the way it will be implemented.
Now create a new file called Extensions.swift
. Here, we are going to add a function to display errors to the user, as we've already seen in the previous chapter. Place the following code in the new file:
import UIKit extension UIViewController { func displayError(message:String){ let alertController = UIAlertController(title: "Error", message: message, preferredStyle: .Alert) let alertAction...