ALRT
An easier constructor for UIAlertController. Present an alert from anywhere like this.
Table of Contents
Features
- Chainable UIAlertController Setup Methods
- Support
.alert
and.actionSheet
UIAlertController.Style - Support
UITextfield
UIAlertAction(.alert
only) - Returns
Result
whether an alert is successfully displayed. In other words, Unit Testable.
Requirements
- Xcode 10.2+
- Swift 5.0
- iOS 9.0+
Installation
Carthage
github "mshrwtnb/ALRT" ~> 1.3.7
Cocoapods
pod repo update
pod 'ALRT', '~> 1.3.7'
Usage
Basics
.alert
.actionSheet
Action Types
Each action comes with different UIAlertAction.Style
.
Custom Title
OK and Cancel actions have default titles in English; "OK" and "Cancel".
Here, we're overriding the titles in Japanese.
Action Handling
Each action has handler
that is called when user taps the action.
The closure takes two parameters: UIAlertAction
and [UITextField]?
.
The former is self-explanatory.
The latter is present if text field(s) is/are added to the alert.
Result Handling
show()
has a completion handler that takes Result
.
You can ensure if the alert was shown successfully or not. This is useful for unit tests.
TextField(s)
Textfield(s) can be added to an alert in an use-case such as login.
Changing source ViewController to present from
Although ALRT can present an alert anywhere, you might want to specify a source view controller for some reason. This can be done easily by passing a view controller to show()
.
Default Configuration
Set default tintColor and titles for OK and Cancel buttons.
License
ALRT is released under the MIT license. See LICENSE for details.