WaterStates 0.4.1

WaterStates 0.4.1

Maintained by BarredEwe.

  • By
  • BarredEwe

Simple and ready-made states for the view controller.
The project is at an early stage of development!

Platform License CodeFactor CocoaPods
Swift5 Swift Package Manager


Are you sure tired of writing the same code in all view controllers? Now you can easily and simply call up the necessary states for display, WaterStates will do the rest.

Inside, a state machine(Inspired by MasterWatcher) is used to that determines the delay and decides when to show, hide, or skip the state display.

If you like the project, do not forget to put star ⭐ and follow me on GitHub.


  • Xcode 11.0+

  • Swift 5.0+

  • Ready for use on iOS 9+

Quick Start

Use the WaterStates protocol on the view controller and invoke the state you need using the showState method.

import UIKit
import WaterStates

class ExampleViewController: UIViewController, WaterStates {

    override func viewDidLoad() {

For the action of the states, you need to correspond to a delegate of a certain state, for example: ErrorStateDelegate.

extension ExampleViewController: WaterStatesDelegate {
    func errorActionTapped(with type: StateActionType) {
        // do something
VIPER Quick Start

You need to set the showState method in the ViewInput protocol:

import WaterStates

protocol ExampleViewInput: class {
    func showState(_ state: DefaultState)

Use the WaterStates protocol on the view controller:

import UIKit
import WaterStates

class ExampleViewController: UIViewController, ExampleViewInput, WaterStates { }

In the Presenter, we set the view state using the showState method:

import WaterStates

class ExamplePresenter: ExampleViewOutput {

    weak var view: ViewControllerInput?

    func someMethodd() {

For the action of the states, ViewOutput must correspond to a specific state delegate, for example: ErrorStateDelegate:

protocol ExampleViewOutput: WaterStatesDelegate { }

class ExamplePresenter: ExampleViewOutput {


    func errorActionTapped(with type: StateActionType) {
        // do something

Basic Usage


To set the state in view, you need to call the showState method with the desired state:

public enum State<T> {
    case loading(StateInfo)
    case content(T)
    case error(StateInfo)
    case empty(StateInfo)

// state for example: .loading

Empty state


Error state


Loading state


Content state

showState(.content(/* your content */))

To use the content state, it is necessary to implement showContent method with a type that you need:

// Content type must be your view model, for example - String
func showContent(_ content: String) {
    // do something with your content

If you do not need data for the content state, you cannot implement the showContent method, or you can specify the type of content in the showContent method, as in DefaultState - Any:

func showContent(_ content: Any) {
    // do something


The rest will be added in the near future 😉!



WaterStates is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'WaterStates'

Swift package manager

To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/BarredEwe/WaterStates.git", .upToNextMajor(from: "0.2.0"))

and then specify "WaterStates" as a dependency of the Target in which you wish to use WaterStates.


BarredEwe, [email protected]


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