Guest User

Untitled

a guest
Feb 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. protocol EnumProtocol {
  2. static var startValue: Self { get }
  3. func nextValue() -> Self
  4. }
  5.  
  6. enum FooState: EnumProtocol {
  7. case foo1, foo2
  8. static var startValue: FooState { return .foo1 }
  9. func nextValue() -> FooState {
  10. switch self {
  11. case .foo1:
  12. return .foo2
  13. case .foo2:
  14. return .foo1
  15. }
  16. }
  17. }
  18.  
  19. enum BarState: EnumProtocol {
  20. case bar
  21. static var startValue: BarState { return .bar }
  22. func nextValue() -> BarState {
  23. return .bar
  24. }
  25. }
  26.  
  27.  
  28. class BaseClass<T: EnumProtocol> {
  29. var state = T.startValue
  30. }
  31.  
  32. class FooClass: BaseClass<FooState> {
  33. }
  34.  
  35. class BarClass: BaseClass<BarState> {
  36. }
  37.  
  38. let foo = FooClass()
  39. let bar = BarClass()
  40. if let test = bar as? BaseClass {
  41. test.state = test.state.nextValue()
  42. }
  43.  
  44. let bar = BarClass()
  45. if let test = bar as? BaseClass<BarState> {
  46. test.state = test.state.nextValue()
  47. }
  48.  
  49. error: generic parameter 'T' could not be inferred in cast to 'Wallet<_>'
Add Comment
Please, Sign In to add comment