Skip to content

Instantly share code, notes, and snippets.

@Savchukv
Created May 31, 2017 14:35
Show Gist options
  • Save Savchukv/8028669bfd6818c08636b30e477a3541 to your computer and use it in GitHub Desktop.
Save Savchukv/8028669bfd6818c08636b30e477a3541 to your computer and use it in GitHub Desktop.
Example to call Alert from different ViewControllers
//
// 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