Last active
January 15, 2016 09:35
-
-
Save tarunon/ea51b3ccdcbca81b8d8d to your computer and use it in GitHub Desktop.
workaround Wildcard error type (is typed)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum Error1<E1: ErrorType> { | |
| case ERROR1(E1) | |
| init?(error: ErrorType) { | |
| if let error = error as? E1 { | |
| self = .ERROR1(error) | |
| } | |
| return nil | |
| } | |
| var error: ErrorType { | |
| switch self { | |
| case .ERROR1(let error): | |
| return error | |
| } | |
| } | |
| func expand<E2: ErrorType>() -> Error2<E1, E2> { | |
| return Error2(error: self.error)! | |
| } | |
| } | |
| enum Error2<E1: ErrorType, E2: ErrorType> { | |
| case ERROR1(E1) | |
| case ERROR2(E2) | |
| init?(error: ErrorType) { | |
| if let error = error as? E1 { | |
| self = .ERROR1(error) | |
| } else if let error = error as? E2 { | |
| self = .ERROR2(error) | |
| } | |
| return nil | |
| } | |
| var error: ErrorType { | |
| switch self { | |
| case .ERROR1(let error): | |
| return error | |
| case .ERROR2(let error): | |
| return error | |
| } | |
| } | |
| func expand<E3: ErrorType>() -> Error3<E1, E2, E3> { | |
| return Error3(error: self.error)! | |
| } | |
| } | |
| enum Error3<E1: ErrorType, E2: ErrorType, E3: ErrorType> { | |
| case ERROR1(E1) | |
| case ERROR2(E2) | |
| case ERROR3(E3) | |
| init?(error: ErrorType) { | |
| if let error = error as? E1 { | |
| self = .ERROR1(error) | |
| } else if let error = error as? E2 { | |
| self = .ERROR2(error) | |
| } else if let error = error as? E3 { | |
| self = .ERROR3(error) | |
| } | |
| return nil | |
| } | |
| var error: ErrorType { | |
| switch self { | |
| case .ERROR1(let error): | |
| return error | |
| case .ERROR2(let error): | |
| return error | |
| case .ERROR3(let error): | |
| return error | |
| } | |
| } | |
| func expand<E4: ErrorType>() -> Error4<E1, E2, E3, E4> { | |
| return Error4(error: self.error)! | |
| } | |
| } | |
| enum Error4<E1: ErrorType, E2: ErrorType, E3: ErrorType, E4: ErrorType> { | |
| case ERROR1(E1) | |
| case ERROR2(E2) | |
| case ERROR3(E3) | |
| case ERROR4(E4) | |
| init?(error: ErrorType) { | |
| if let error = error as? E1 { | |
| self = .ERROR1(error) | |
| } else if let error = error as? E2 { | |
| self = .ERROR2(error) | |
| } else if let error = error as? E3 { | |
| self = .ERROR3(error) | |
| } else if let error = error as? E4 { | |
| self = .ERROR4(error) | |
| } | |
| return nil | |
| } | |
| var error: ErrorType { | |
| switch self { | |
| case .ERROR1(let error): | |
| return error | |
| case .ERROR2(let error): | |
| return error | |
| case .ERROR3(let error): | |
| return error | |
| case .ERROR4(let error): | |
| return error | |
| } | |
| } | |
| // func expand<E5: ErrorType>() -> Error5<E1, E2, E3, E4, E5> { | |
| // return Error5(error: self.error)! | |
| // } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment