Conform a protocol into `CustomError` and `NSError`.
Cast `Error` to `A`, then implicit type cast `Error` to `NSError` work.
Minimum code is here.
import Foundation
protocol MyCustomErrorProtocol {
var hoge: Int { get }
}
struct MyCustomError: Error, MyCustomErrorProtocol {
var hoge: Int {
return 1
}
}
extension NSError: MyCustomErrorProtocol {
var hoge: Int {
return 0
}
}
let error: Error = MyCustomError()
if let cError = error as? MyCustomErrorProtocol {
cError.hoge // 0 (If Swift 3.0 then 1)
}
Environment
Swift 3.1, Xcode 8.3, PlaygroundAdditional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, Runtime | |Assignee | @DougGregor | |Priority | Medium | md5: 6da17e3a189bae0abaaf29a0dc66b997Issue Description:
1. Make a protocol `A`.
Minimum code is here.