klAlert 1.0.8

klAlert 1.0.8

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jul 2019
SPMSupports SPM

Maintained by Ken Laws.



klAlert 1.0.8

klAlert

CI Status Version License Platform

Example

UIAlertController is nice and all, but it means having to write a few lines of code where before one call was often all you'd need. klAlert is a class with functions that let you create and handle the results of a modern alert in just one call:

Alert().withButtons(title: "Confirm",
				msg: "Confirm an action.",
				cancel: "Cancel",
				buttons: ["OK"]) { (index) in
					guard result == 1 else { return }
					// Do the thing
				}

Current Version: 1.0.8

A complete restructuring.

Installation

CocoaPods

  1. Add the following to your Podfile:
use_frameworks! #if this isn't already in your podfile
pod "klAlert"
  1. Run pod install.
  2. Enjoy.

Documentation

Until I have ample time, note that you can find at least simple examples of usage in the Demo app.

Functions for the Class Alert

func withOneButton(title: String, msg: String, btn: String)

Shows an alert with one button. There is no completion hander. It simply vanishes when the user taps the button.
Parameters
title: Title at top of alert
msg: Explanatory alert text
btn: Text for the button

func withButtons(title: String?, msg: String, cancel: String?, buttons: [String], handler: @escaping (_ result: Int) -> ())

Shows an alert with one or more buttons. After a tap, it runs the completion handler using an index to indicate which button the user pressed. Buttons are displayed from top to bottom or left to right if there are only two. Cancel is always displayed at the bottom or left.
Parameters
title?: Title at top of alert (optional) msg: Explanatory alert text cancel?: Text for the "Cancel" button (optional) buttons: An array of strings for the button titles
handler: closure with an Int indicating which button was tapped (cancel = 0, btn1 = 1...)

func asAPopup(source: UIView?, title: String?, msg: String?, cancel: String?, buttons: [String], handler: @escaping (_ result: Int) -> ())

Shows a popup alert with a number of buttons, runs the completion handler once the user makes a choice and returns the index of the tapped button (cancel = 0.) Parameters
source?: The view from which the popover emanates (REQUIRED if presented on an iPad, otherwise optional)
title?: Large title at top of alert (optional) msg?: Small subtitle. (optional) cancel?: Text for the "Cancel" button (optional) buttons: Array of Strings with button titles
handler: closure with an Int indicating which button was tapped (cancel = 0, btn1 = 1...)

Author

kenlaws, [email protected]

License

klAlert is available under the MIT license. See the LICENSE file for more info.