Last active
July 6, 2020 21:42
-
-
Save BrunoScheltzke/93cdeadc2b1ffb5163492f664a6049c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // | |
| // UIViewController.swift | |
| // | |
| // Created by Bruno Scheltzke on 04/06/20. | |
| // Copyright © 2020 Bruno Scheltzke All rights reserved. | |
| // | |
| import UIKit | |
| extension UIViewController { | |
| func present(message: String) { | |
| let alert = UIAlertController(title: "Puxa vida 🥺", message: message, preferredStyle: .alert) | |
| alert.view.tintColor = .systemBlue | |
| let action = UIAlertAction(title: "OK", style: .default, handler: nil) | |
| alert.addAction(action) | |
| DispatchQueue.main.async { | |
| self.present(alert, animated: true, completion: nil) | |
| } | |
| } | |
| func present(error: Error) { | |
| present(message: error.localizedDescription) | |
| } | |
| func addHideKeyboardOnTouch() { | |
| let tap = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) | |
| tap.cancelsTouchesInView = false | |
| view.addGestureRecognizer(tap) | |
| } | |
| @objc func dismissKeyboard() { | |
| view.endEditing(true) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment