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:
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)
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.
github "rockbruno/ErrorKing" "master"
pod "ErrorKing"
rockbruno, brunorochaesilva@gmail.com
ErrorKing is available under the MIT license. See the LICENSE file for more info.