首页 > 解决方案 > 通用枚举的 Swift 默认值

问题描述

我有一个像这样的泛型类型的枚举:

public enum ServiceError<FailureResponse: Decodable>: Swift.Error {
    case other(Error)
    case underlying(statusCode: Int, response: URLResponse)
    case decodeError(error: FailureResponse?)
}

我可以将默认类型设置为FailureResponse?如果我能做到这一点,任何使用我的库的人都不会被迫传递泛型类型

标签: iosswiftgenericsenums

解决方案


推荐阅读