我无法找出访问枚举的原始值的语法。下面的代码应该说明我正在尝试做什么。在快速枚举中访问值
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
比我的回答更好!忘了你可以匹配那种模式。 –