Latest 0.0.2
Homepage https://github.com/lfarah/LFAlertController
License MIT
Platforms ios 8.0, requires ARC
Authors

Version
License
Platform
Language

UIAlertController Swift extension with handler inside initialization :large_orange_diamond:

Why? Because UIAlertController has handlers inside each action, forcing the developers to have duplicated code. Instead, we can have a switch inside a global handler that is called when any action inside the UIAlertController is called

How to install

Using the Swift file:

Drag the LFAlertController.swift from /Sources to your project

Using CocoaPods:

Don’t forget to add use_frameworks! at the top of your Podfile

pod 'LFAlertController'

Using SPM

  .Package(url: "https://github.com/awesome-labs/LFAlertController.git", majorVersion: 0)

How to Use

Initializing UIAlertActions

let action1 = UIAlertAction(title: "Second Action", style: .Default)

Initializing UIAlertController

UIAlertController with Handler

self.controller = UIAlertController(title: "hey", message: "ho", preferredStyle: .Alert,actions:[action0,action1])
{ (action,index) -> () in

  //Printing index of Action
  print("(index) - (action.title!)")
}
Show UIAlertController
self.controller.show()

Other options

UIAlertAction with handler

let action0 = UIAlertAction(title: "First Action", style: .Default, handler: nil)

UIAlertController without Handler

self.controller = UIAlertController(title: "hey", message: "ho", preferredStyle: .Alert, actions: [action0,action1])

Latest podspec

{
    "name": "LFAlertController",
    "version": "0.0.2",
    "summary": "UIAlertController with global handler :large_orange_diamond:",
    "description": "UIAlertController Swift extension with handler inside initialization",
    "homepage": "https://github.com/lfarah/LFAlertController",
    "license": "MIT",
    "authors": {
        "lucasfarah": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lfarah/LFAlertController.git",
        "tag": "0.0.2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Source/LFAlertController.swift",
    "requires_arc": true,
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This