Skip to content

Instantly share code, notes, and snippets.

@LH17
Created June 2, 2017 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LH17/2dcc5cea3c249e67d9bd6cf565069a50 to your computer and use it in GitHub Desktop.
Save LH17/2dcc5cea3c249e67d9bd6cf565069a50 to your computer and use it in GitHub Desktop.
StateManager Singleton class
class StateManager {
static let sharedInstance = StateManager()
var viewStore: [String: UIView] = [:]
// Associates a view for the given state
public func addView(_ view: UIView, forState state: String, superview: UIView) {
viewStore[state] = view
superview.addSubview(view)
}
// Remove all views
public func removeAllViews() {
for (_, view) in self.viewStore {
view.removeFromSuperview()
viewStore = [:]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment