我将singleResult(类型为Result<FAQResult>)转换为FAQResult时发生崩溃

fileprivate var fAQS = [FAQ]()

 when(resolved: task).then { (result) -> Void in
       let singleResult:Result<FAQResult> = result.first!
       let whereItCrashes = singleResult as! FAQResult
       self.fAQS =  whereItCrashes.result!
    }



下面的代码来自项目中使用的核心 promise Pod。它所做的一切都给我带来了.boolValue,但我需要将其从
结果转换为FAQResult。
    public enum Result<T> {
    /// Fulfillment
    case fulfilled(T)
    /// Rejection
    case rejected(Error)

    init(_ resolution: Resolution<T>) {
        switch resolution {
        case .fulfilled(let value):
            self = .fulfilled(value)
        case .rejected(let error, _):
            self = .rejected(error)
        }
    }

    /**
     - Returns: `true` if the result is `fulfilled` or `false` if it is `rejected`.
     */
    public var boolValue: Bool {
        switch self {
        case .fulfilled:
            return true
        case .rejected:
            return false
        }
    }
}

关于如何使其正确投放的任何解决方案?

最佳答案

您可以像这样将新的计算属性value添加到Result<T>中:

/**
 - Returns: actual fulfilled `value` if the result is `fulfilled` or `nil` if it is `rejected`.
*/
public var value: T? {
    switch self {
    case .fulfilled(let value):
        return value
    case .rejected:
        return nil
    }
}

然后singleResult.value将返回您FAQResult

10-06 02:50