Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ ALRT Public

An easier constructor for UIAlertController. Present an alert from anywhere.

License

mshrwtnb/ALRT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status codecov Carthage compatible Cocoapods

ALRT

ALRT is an easy-to-create UIAlertController. It aims to be an AL(R)Ternative to tedious implementation process.

Image

Features

  • Call-site-friendly. See Usages.
  • Chainable
  • Can add UITextField(s) and handle their values when a certain UIAlertAction button is clicked.
  • Can handle the result of show() action both .success and .failure

Usages

Alert with OK / Cancel buttons

import ALRT

// alert without title/message
ALRT.create(.alert)
    .addOK()
    .addCancel()
    .show()

// alert with title
ALRT.create(.alert, title: "Title")
    .addOK()
    .addCancel()
    .show()

// alert with title and message
ALRT.create(.alert, title: "Title", message: "Message")
    .addOK()
    .addCancel()
    .show()

ActionSheet

UIAlertControllerStyle.ActionSheet is supported.

ALRT.create(.actionSheet, title: "Choose your destination")
    .configurePopoverPresentation {
        // set popover.barButtonItem or popover.sourceView for iPad
        popover in
        popover?.barButtonItem = sender
    }
    .addAction("New York") { action, _ in
        print("New York has been selected")
    }
    .addAction("Paris")
    .addAction("London")
    .addDestructive("None of the above")
    .show()

Alert with two textfields

UIAlertController.textFields can be accessed asynchronously right after the OK button is tapped. Also you are able to know if the alert or action sheet is displayed or not.

ALRT.create(.alert, title: "Login", message: "Please enter your credentials")
    .addTextField { textField in
        textField.placeholder = "Username"
        textField.accessibilityIdentifier = "Username"
    }
    .addTextField { textField in
        textField.placeholder = "Password"
        textField.accessibilityIdentifier = "Password"
        textField.isSecureTextEntry = true
    }
    .addCancel()
    .addOK() { alert, textFields in
        textFields?
            .flatMap { (placeholder: $0.placeholder ?? "No Placeholder", text: $0.text ?? "No Text") }
            .forEach { print("\($0.placeholder) => \($0.text)") }
    }
    .show { result in
        switch result {
        case .success:
            print("The alert is displayed.")

        case .failure(let error):
            print("The alert is not displayed. Error => \(error)")
        }
    }

Requirements

  • Xcode 8.0 (Swift 3.0) or later
  • iOS 8.0 or later

Installation

Cocoapods

Add to your Podfile and run pod install.

platform :ios, '8.0'

target YOUR_TARGET do
  use_frameworks!
  pod "ALRT"
end

Carthage

Add to your Cartfile.

github "mshrwtnb/ALRT"

Documentation

About

An easier constructor for UIAlertController. Present an alert from anywhere.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •