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

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ALRT is a call-site-friendly UIAlertController framework that aims to be an AL(R)Ternative to tedious UIAlertController implementation process.

Similar snippets will no longer mess up your project.

Image

Features

  • Call-site-friendly. See Usages
  • Chainable UIAlertController setup both Alert and ActionSheet styles
  • Add UITextField(s) and handle their values when a certain UIAlertAction button is clicked
  • Preferred Action Support
  • Can handle the result of show() action both .Success and .Failure

Usages

Alert with OK / Cancel buttons

import ALRT

ALRT.create(.alert, title: "Error", message: "No item found")
    .addOK()
    .addAction("No Way!", preferred: true) // preferredAction is available iOS 9.0 or later
    .show()

ActionSheet

UIAlertControllerStyle.ActionSheet is supported.

ALRT.create(.actionSheet, title: "Destination", message: "Please select your destination")
        .configurePopoverPresentation {
            // set popover.barButtonItem or popover.sourceView for iPad
            popover in
            popover?.barButtonItem = sender
        }
        .addAction("New York") { action, textFields in print("New York has been selected") }
        .addAction("Paris")
        .addAction("London")
        .addDestructive("Not interested")
        .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"
         }
         .addTextField { textField in
             textField.placeholder = "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(completion: { 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)
  • 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

  •  
  •  
  •  
  •