Simple and ready-made states for the view controller.
The project is at an early stage of development!
Introduction
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.
Requirements
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.
In the Presenter, we set the view state using the showState method:
import WaterStates
class ExamplePresenter: ExampleViewOutput {
weak var view: ViewControllerInput?
func someMethodd() {
view?.showState(.loading)
}
}
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
States
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
showState(.loading)
Empty state
showState(.empty)
Error state
showState(.error)
Loading state
showState(.loading)
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
}
Configarations
The rest will be added in the near future 😉!
Installation
CocoaPods
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:
Simple and ready-made states for the view controller.
The project is at an early stage of development!
Introduction
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.Requirements
11.0
+5.0
+iOS 9
+Quick Start
Use the
WaterStates
protocol on the view controller and invoke the state you need using theshowState
method.For the action of the states, you need to correspond to a delegate of a certain state, for example:
ErrorStateDelegate
.VIPER Quick Start
You need to set the
showState
method in theViewInput
protocol:Use the
WaterStates
protocol on the view controller:In the
Presenter
, we set the view state using theshowState
method:For the action of the states,
ViewOutput
must correspond to a specific state delegate, for example:ErrorStateDelegate
:Basic Usage
States
To set the
state
in view, you need to call theshowState
method with the desired state:Empty state
Error state
Loading state
Content state
To use the content state, it is necessary to implement
showContent
method with a type that you need: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 theshowContent
method, as inDefaultState
-Any
:Configarations
The rest will be added in the near future 😉!
Installation
CocoaPods
WaterStates is available through CocoaPods. To install it, simply add the following line to your Podfile:
Swift package manager
To integrate using Apple’s Swift package manager, add the following as a dependency to your
Package.swift
:and then specify
"WaterStates"
as a dependency of the Target in which you wish to use WaterStates.Author
License
WaterStates
is available under the MIT license. See the LICENSE file for more info.