Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewModelling.swift
- // Headlines
- //
- // Created by Callum Trounce on 02/05/2019.
- // Copyright © 2019 Callum Trounce. All rights reserved.
- //
- import Foundation
- /// Indicates presentation state
- ///
- /// - idle: not loading / doing anything
- /// - loading: loading data.
- /// - result: result has been recieved.
- enum PresentationState<T> {
- case idle
- case loading
- case result(Result<T, Error>)
- }
- /// Protocol which defines basic requirements for viewmodelling.
- protocol ViewModelling {
- associatedtype ResultData
- /// Indicate current state
- var currentState: PresentationState<ResultData> { get set }
- /// Quick way to access the current data stored within the current state.
- var data: ResultData? { get }
- /// Closure indicating that the current state has been updated.
- var stateUpdated: ((PresentationState<ResultData>) -> Void)? { get set }
- /// Indicate that the view controller has finished loading
- func viewDidLoad()
- /// Clean / wipe data, expectation is to clear memory
- func clean()
- }
- /// Indicates that the data source can be refreshed.
- protocol Refreshing {
- /// Indicate that the refresh has been pulled on the table view
- func refreshPulled()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement