Last active
June 2, 2017 12:28
-
-
Save LH17/4e01fa12d2eecf37210cbe182c2a5732 to your computer and use it in GitHub Desktop.
ViewStateProtocol extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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