Skip to content

Instantly share code, notes, and snippets.

View elenamene's full-sized avatar

Elena Meneghini elenamene

  • Barcelona, Spain
View GitHub Profile
@elenamene
elenamene / UIAlertController+TextField.swift
Created June 1, 2019 15:37 — forked from ole/UIAlertController+TextField.swift
A UIAlertController with a text field and the ability to perform validation on the text the user has entered while the alert is on screen. The OK button is only enabled when the entered text passes validation. More info: https://oleb.net/2018/uialertcontroller-textfield/
import UIKit
/// A validation rule for text input.
public enum TextValidationRule {
/// Any input is valid, including an empty string.
case noRestriction
/// The input must not be empty.
case nonEmpty
/// The enitre input must match a regular expression. A matching substring is not enough.
case regularExpression(NSRegularExpression)
@elenamene
elenamene / UIAlertController.swift
Created May 29, 2019 14:11 — forked from rodydavis/UIAlertController.swift
Swift 4 Alert Controller Examples
//Updated for Swift 4
//One Button
class ViewController: UIViewController {
@IBAction func showAlertButtonTapped(_ sender: UIButton) {
// create the alert
let alert = UIAlertController(title: "My Title", message: "This is my message.", preferredStyle: UIAlertControllerStyle.alert)