Skip to content

Instantly share code, notes, and snippets.

@LH17
Created June 2, 2017 12:33
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