Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ViewStateProtocol extension
extension ViewStateProtocol where Self: UIViewController {
..........
// Manages and adds different views on the basis of the state
func addView(withState state: StatesType) {
// error state, empty state & loading state
switch state {
case .loading:
// calls state manager to add a laoding view
stateManager?.addView(loadingView!, forState: StatesType.loading.rawValue, superview: view)
case .error:
// calls state manager to add an error view
stateManager?.addView(errorView!, forState: StatesType.error.rawValue, superview: view)
case .empty:
// calls state manager to add an empty view
stateManager?.addView(emptyView!, forState: StatesType.empty.rawValue, superview: view)
default:
// removes all the views for managing states
removeAllViews()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment