Skip to content

Instantly share code, notes, and snippets.

@vasilevkin
Created November 23, 2018 13:40
Show Gist options
  • Save vasilevkin/b1e2e7c17220c60f1b32daf5b8ded717 to your computer and use it in GitHub Desktop.
Save vasilevkin/b1e2e7c17220c60f1b32daf5b8ded717 to your computer and use it in GitHub Desktop.
enum ErrorsWhenCasting : Error {
case wrongType
}
private static func value<T>(valueRaw: LoginResponse) throws -> T {
guard let castedValue = valueRaw as? T else {
throw ErrorsWhenCasting.wrongType
}
return castedValue
}
do {
let valueNew = value(valueRaw: response)
} catch ErrorsWhenCasting.wrongType {
print("Unable to cast, catched wrong type error")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment