Skip to content

Instantly share code, notes, and snippets.

@LH17
Last active June 2, 2017 12:28
Show Gist options
  • Save LH17/4e01fa12d2eecf37210cbe182c2a5732 to your computer and use it in GitHub Desktop.
Save LH17/4e01fa12d2eecf37210cbe182c2a5732 to your computer and use it in GitHub Desktop.
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