我無法找出訪問枚舉的原始值的語法。下面的代碼應該說明我正在嘗試做什麼。在快速枚舉中訪問值
enum Result<T, U> {
case Success(T)
case Failure(U)
}
struct MyError: ErrorType {
var status: Int = 0
var message: String = "An undefined error has occured."
init(status: Int, message: String) {
self.status = status
self.message = message
}
}
let goodResult: Result<String, MyError> = .Success("Some example data")
let badResult: Result<String, MyError> = .Failure(MyError(status: 401, message: "Unauthorized"))
var a: String = goodResult //<--- How do I get the string out of here?
var b: MyError = badResult //<--- How do I get the error out of here?
是第二次離開發布相同+1 – Kametrixom
比我的回答更好!忘了你可以匹配那種模式。 –