Created
May 31, 2017 14:35
-
-
Save Savchukv/8028669bfd6818c08636b30e477a3541 to your computer and use it in GitHub Desktop.
Example to call Alert from different ViewControllers
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
// | |
// Alert.swift | |
// | |
// Created by Vasiliy Savchuk on 16.12.16. | |
// Copyright © All rights reserved. | |
// | |
// Usage this snippet: | |
// to call - displayAlert(title: "Oops!", message: "Error", viewController: self) | |
import Foundation | |
import UIKit | |
func displayAlert(title: String, message: String, viewController: UIViewController) { | |
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) | |
let action = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil) | |
let actionRetry = UIAlertAction(title: "Retry", style: UIAlertActionStyle.cancel) {action in | |
//execute some code when this option is selected | |
} | |
alert.addAction(action) | |
alert.addAction(actionRetry) | |
viewController.present(alert, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment