Skip to content

Instantly share code, notes, and snippets.

@yabenatti
Created November 10, 2017 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yabenatti/438aaf14ceff2320745e736c25cfdc9b to your computer and use it in GitHub Desktop.
Save yabenatti/438aaf14ceff2320745e736c25cfdc9b to your computer and use it in GitHub Desktop.
DelegateTutorialFirstViewController
import UIKit
class FirstViewController: UIViewController, SecondViewControllerProtocol {
// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "FirstToSecondSegue" {
if let vc = segue.destination as? SecondViewControllerProtocol {
vc.delegate = self
}
}
}
//MARK: - SecondViewControllerDelegate
func didDoSomethingOnSecondViewController(message: String) {
let alert = UIAlertController(title: "Delegate", message: "\(message)", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .cancel, handler: nil);
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment