Advertisement
Guest User

Untitled

a guest
May 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. //
  2. // ViewModelling.swift
  3. // Headlines
  4. //
  5. // Created by Callum Trounce on 02/05/2019.
  6. // Copyright © 2019 Callum Trounce. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10.  
  11. /// Indicates presentation state
  12. ///
  13. /// - idle: not loading / doing anything
  14. /// - loading: loading data.
  15. /// - result: result has been recieved.
  16. enum PresentationState<T> {
  17. case idle
  18. case loading
  19. case result(Result<T, Error>)
  20. }
  21.  
  22. /// Protocol which defines basic requirements for viewmodelling.
  23. protocol ViewModelling {
  24.  
  25. associatedtype ResultData
  26.  
  27. /// Indicate current state
  28. var currentState: PresentationState<ResultData> { get set }
  29.  
  30. /// Quick way to access the current data stored within the current state.
  31. var data: ResultData? { get }
  32.  
  33. /// Closure indicating that the current state has been updated.
  34. var stateUpdated: ((PresentationState<ResultData>) -> Void)? { get set }
  35.  
  36. /// Indicate that the view controller has finished loading
  37. func viewDidLoad()
  38.  
  39. /// Clean / wipe data, expectation is to clear memory
  40. func clean()
  41. }
  42.  
  43. /// Indicates that the data source can be refreshed.
  44. protocol Refreshing {
  45.  
  46. /// Indicate that the refresh has been pulled on the table view
  47. func refreshPulled()
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement