Skip to content

Instantly share code, notes, and snippets.

@Sonictherocketman
Last active August 18, 2016 01:14
Show Gist options
  • Save Sonictherocketman/ef3f31334a9406212714bbf086b858f2 to your computer and use it in GitHub Desktop.
Save Sonictherocketman/ef3f31334a9406212714bbf086b858f2 to your computer and use it in GitHub Desktop.
An example of guard statement awesomeness.
class MyViewController : UITableViewController {
// ...
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let activity = self.activities
// If anything isn't right, deselect the row and exit.
guard activity.openable else {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
return
}
guard let task = self.getTask(activity) else {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
return
}
// Looks like everything is fine. That means we can open up the detail view.
let taskViewController = DetailViewController(task: task, taskRunUUID: NSUUID(), identifier: activity.identifier)
taskViewController.delegate = self
navigationController?.presentViewController(taskViewController, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment