Giter Site home page Giter Site logo

mironal / shorthandalert Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 1.85 MB

A helpful UIAlertController extension and Builder for the slothful human.

Home Page: https://mironal.github.io/ShortHandAlert/

License: MIT License

Objective-C 16.26% Swift 82.84% Shell 0.90%
swift objective-c ios uialertcontroller

shorthandalert's Issues

Add action according to situation

feel lazy ๐Ÿ˜ฉ

let alert = UIAlertController(blah blah blah)

// ๐Ÿ˜ฉ๐Ÿ˜ฉ๐Ÿ˜ฉ๐Ÿ˜ฉ๐Ÿ˜ฉ๐Ÿ˜ฉ๐Ÿ˜ฉ๐Ÿ˜ฉ๐Ÿ˜ฉ
if someSituation {
  alert.default("Hoge action") { _ in
    // do something
  }
}

alert.cancel()
  .present(in: self)

awesome ๐Ÿ˜„

UIAlertController(blah blah blah)
  .default("Hoge action", addAction: someSituation) { _ in
    // do something
  }
  .cancel()
  .present(in: self)

support selector

We often write blocks that just call methods in this way.

func doSomething() {
}

func showActionSheet() {
  let alert = UIAlertController(title: "title", message: nil, preferredStyle: .actionSheet)

   alert.addAction(UIAlertAction(title: "Some", style: .default, handler: { _ in
      doSomething()
   }))

   alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))

   present(alert, animated: true)
}

Proposal

func doSomething() {
}

func showActionSheet() {
  UIAlertController(title: "Title", message: nil, preferredStyle: .actionSheet)
      .default("Some", target: self, selector: #selector(doSomething)
      .cancel()
      .present(in: self)
}

support Error Alert Shorthand

No more

let alert = UIAlertController(title: "Error", message: error.localizedDescription, style: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)
present(alert)
let alert = UIAlertController(title: "Error", message: error.localizedDescription, style: .alert)
alert.addAction(UIAlertAction(title: "Recover", style: .default, handler: { _ in
  // do something...
})
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
present(alert)

Shorthand

Alert(error, title: "optional title").present(in: self)
Alert(error, title: "optional title"){ _ in
  // do something...
}.present(in: self)

Hummmmmmmmmmmmmm.....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.