ALRT is an easy-to-create UIAlertController. It aims to be an AL(R)Ternative to tedious implementation process.
- 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
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()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()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)")
}
}- Xcode 8.0 (Swift 3.0) or later
- iOS 8.0 or later
Add to your Podfile and run pod install.
platform :ios, '8.0'
target YOUR_TARGET do
use_frameworks!
pod "ALRT"
end
Add to your Cartfile.
github "mshrwtnb/ALRT"