【问题标题】:Result enum overridden by other library结果枚举被其他库覆盖
【发布时间】:2020-04-20 23:07:39
【问题描述】:

我正在尝试使用 Swift 的 Result 枚举。但它似乎被我正在使用的 pod (Auth0) 覆盖。

pod 有一个类似的枚举结果。像这样的

public enum Result<T> {
    case success(result: T)
    case failure(error: Error)
}

我如何使用 Swift.Results 提供的而不是这个。因为它迫使我使用来自 Auth0 的那个。

编辑: 更多关于错误 当我尝试将函数的返回类型设置为 Result&lt;String,Error&gt; 时,它给了我错误 Generic type 'Result' specialized with too many type parameters (got 2, but expected 1)

【问题讨论】:

  • it forces me to use the one from Auth0 — 你能扩展一下吗?它何时、如何以及在何处迫使您这样做?
  • 它与 swift 提供的枚举相同...有什么问题?
  • 尝试Swift.Result&lt;String,Error&gt; 覆盖它
  • 请添加您的代码sn-p

标签: swift error-handling enums


【解决方案1】:

如果要使用具体的定义,需要具体声明,即:

    var result: Swift.Result<String, Error> = .success("Test")

OAuth 会覆盖它,因此它只需要 1 个值,因此会出现错误,您可以像使用 OAuth 一样

    var result: Result<String> = .success("Test")

【讨论】:

  • 是的,已经尝试过了,但由于某种原因它之前没有编译过。现在我再次尝试它。 XCode 有时很奇怪。感谢您的提示:-)
猜你喜欢
  • 2010-09-19
  • 1970-01-01
  • 1970-01-01
  • 2021-01-23
  • 2020-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-23
相关资源
最近更新 更多