ErrorKing 0.2.0

ErrorKing 0.2.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Apr 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Bruno Rocha, BrunoRocha.



ErrorKing 0.2.0

  • By
  • rockbruno

ErrorKing

Smart error alerts and full-fledged empty state views on your ViewControllers just a protocol inheritance away.

To add ErrorKing to your ViewController, extend it with the ErrorProne protocol:

extension MyViewController: ErrorProne {}

That’s it! You can now call your ViewController’s new property: errorKing, and see it’s effects.

self.errorKing.setError(title: "Damn!", description: "Sorry for that.", emptyStateText: "Something happened :(")

Now, the next time your ViewController is visible (if the user triggered a load but pushed another screen, for example), ErrorKing will display:

Error EmptyState

Additional Customization

To dictate what happens when the empty state’s reload button is touched, override ErrorProne’s errorKingEmptyStateReloadButtonTouched:

extension MyViewController: ErrorProne {
    func errorKingEmptyStateReloadButtonTouched() {
        //load my stuff again
        errorKing.errorKingEmptyStateReloadButtonTouched() //This will remove the empty state from the screen.
    }
}

You can also program what happens before the empty state is displayed:

func actionBeforeDisplayingErrorKingEmptyState() {
    //do something before displaying the empty state screen, like disabling your tableView's scrolling
    errorKing.actionBeforeDisplayingErrorKingEmptyState() //Sets up and displays the empty state screen.
}

…and change the empty state’s frame if needed:

self.errorKing?.setEmptyStateFrame(rect: aFrame)

Providing your own EmptyState screen

To add your own Empty State view, simply make a .swift/.xib that has ErrorKingEmptyStateView as it’s class or superclass and link the corresponding outlets, if you used a .xib, or set errorLabel and init a button that triggers tryAgain:, if you use view code. After that, call:

self.errorKing.setEmptyStateView(toView: myCustomEmptyState)

You can see it in action on the Example project.

ExampleEmptyState

Installation

Author

rockbruno, [email protected]

License

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