Skip to content

dalu93/SimplyAlert

Repository files navigation

SimplyAlert

Build Status Cocoapods version

Swifty way to use UIAlertController and UIAlertAction

Example

Initialize UIAlertAction easily.

// Here I'm using the default text that is "Cancel". You can override it
// by calling `UIAlertAction.Cancel("My text") { print($0) }`
let cancelAction = UIAlertAction.Cancel { print($0) }

Initialize your UIAlertController extremely fast and add your action to it. Then present it

// Using the chain provided by `add(_:)` that returns 
// the same `UIAlertController` instance
let _ = UIAlertController.alertWith(
    title: "My title",
    message: "My message"
).add(cancelAction)
.presentIn(self) // self is the UIViewController instance

This is exactly equivalent to

let cancelAction = UIAlertAction(
    title: "Cancel",
    style: .Cancel,
    handler: { print($0) }
)

let alert = UIAlertController(
    title: "My title",
    message: "My message",
    preferredStyle: .Alert
)

alert.addAction(cancelAction)

presentViewController(
    alert,
    animated: true,
    completion: nil
)

Installation

pod 'SimplyAlert', '~> 1.0'
import PackageDescription

let package = Package(
    name: "SimplyAlert",
    dependencies: [
        .Package(url: "https://github.com/dalu93/SimplyAlert", "1.0"),
    ]
)

License

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

About

Functional UIAlertController in Swift 🔶

Resources

License

Stars

Watchers

Forks

Packages

No packages published