Last active
August 18, 2016 01:14
-
-
Save Sonictherocketman/ef3f31334a9406212714bbf086b858f2 to your computer and use it in GitHub Desktop.
An example of guard statement awesomeness.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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