Skip to content

Instantly share code, notes, and snippets.

@LH17
LH17 / StatesType.swift
Created June 2, 2017 12:25
StatesType enum
enum StatesType: String {
case error = "error"
case empty = "empty"
case loading = "loading"
case none = "none"
}
@LH17
LH17 / ViewStateProtocolExtension_AddViews.swift
Last active June 2, 2017 12:28
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)
@LH17
LH17 / ViewStateProtocolExtension.swift
Last active June 3, 2017 14:13
ViewStateProtocol extension
extension ViewStateProtocol where Self: UIViewController {
// State manager class to remove/add views
var stateManager: StateManager? {
return StateManager.sharedInstance
}
// Loading view
var loadingView: UIView? {
return LoadingView(frame: UIScreen.main.bounds)
@LH17
LH17 / ViewStateProtocol.swift
Created June 2, 2017 12:10
ViewStateProtocol protocol
protocol ViewStateProtocol: class {
var stateManager: StateManager? { get }
var loadingView: UIView? { get }
var errorView: UIView? { get }
var emptyView: UIView? { get }
var errorMessage: String? { get set }
func addView(withState state: StatesType)
}