Skip to content

Instantly share code, notes, and snippets.

@BrunoScheltzke
Last active July 6, 2020 21:42
Show Gist options
  • Select an option

  • Save BrunoScheltzke/93cdeadc2b1ffb5163492f664a6049c3 to your computer and use it in GitHub Desktop.

Select an option

Save BrunoScheltzke/93cdeadc2b1ffb5163492f664a6049c3 to your computer and use it in GitHub Desktop.
//
// 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