Created
June 2, 2017 12:33
-
-
Save LH17/2dcc5cea3c249e67d9bd6cf565069a50 to your computer and use it in GitHub Desktop.
StateManager Singleton class
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
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