Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protocol EnumProtocol {
- static var startValue: Self { get }
- func nextValue() -> Self
- }
- enum FooState: EnumProtocol {
- case foo1, foo2
- static var startValue: FooState { return .foo1 }
- func nextValue() -> FooState {
- switch self {
- case .foo1:
- return .foo2
- case .foo2:
- return .foo1
- }
- }
- }
- enum BarState: EnumProtocol {
- case bar
- static var startValue: BarState { return .bar }
- func nextValue() -> BarState {
- return .bar
- }
- }
- class BaseClass<T: EnumProtocol> {
- var state = T.startValue
- }
- class FooClass: BaseClass<FooState> {
- }
- class BarClass: BaseClass<BarState> {
- }
- let foo = FooClass()
- let bar = BarClass()
- if let test = bar as? BaseClass {
- test.state = test.state.nextValue()
- }
- let bar = BarClass()
- if let test = bar as? BaseClass<BarState> {
- test.state = test.state.nextValue()
- }
- error: generic parameter 'T' could not be inferred in cast to 'Wallet<_>'
Add Comment
Please, Sign In to add comment