Latest 0.2.0
Homepage https://github.com/rockbruno/ErrorKing
License MIT
Platforms ios 9.0
Authors

CI Status
Carthage compatible
Version
License
Platform

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

Carthage

github "rockbruno/ErrorKing" "master"

CocoaPods

pod "ErrorKing"

Author

rockbruno, [email protected]

License

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

Latest podspec

{
    "name": "ErrorKing",
    "version": "0.2.0",
    "summary": "Swift Lib to make displaying errors and emptyState screens a very easy task",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/rockbruno/ErrorKing",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "rockbruno": "[email protected]"
    },
    "source": {
        "git": "https://github.com/rockbruno/ErrorKing.git",
        "branch": "master",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "Sources/Classes/**/*",
    "resource_bundles": {
        "ErrorKing": [
            "Sources/Assets/EKAssets.xcassets"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This