【问题标题】:Swift not inferring enum type from other view controller directlySwift 不直接从其他视图控制器推断枚举类型
【发布时间】:2019-12-16 09:53:52
【问题描述】:

我已经在视图控制器中声明了一些枚举值并尝试在另一个类中访问,但是对于某些枚举我可以直接推断,但对于其他我需要使用类名。示例代码

class MyRootViewController: UIViewController {
    enum Animation {
        case left
        case right
        case top
        case bottom
        case none
    }
  //some code
}

class OtherViewController: UIViewController {
  enum Configurations {
        case config
        case version
        case type
    }
  //some code
}



 class Utility {
   func addConfiguration(_ config: Configurations) {
    //some code
    }

   func showAnimation(_ animation: MyRootViewController.Animation) {
   //Some code
   }
  }

如果我在 Utitlity 的第二个函数中声明 func showAnimation(_ animation: Animation) 它会抛出错误“使用未声明的标识符动画”

为什么在第一种方法中我没有提到类但在第二种方法中没有?

【问题讨论】:

  • 无论如何都不行,我想你还有Configurations的课,你能检查确认一下吗?

标签: ios xcode enums xcode10 swift4.2


【解决方案1】:

仅供参考: addConfiguration 给出错误。

请检查您的source code,我确定任何framework 都有Configurations classenum 在您的项目中定义。

就是这样

【讨论】:

  • 是的,看起来 pod 文件中的框架有一个类似的枚举,定义了相同的名称配置。
【解决方案2】:

请检查您的第一个功能是否不起作用。

它抛出错误“使用未声明的标识符动画”

所以您首先更改了源代码。 谢谢..

【讨论】:

    猜你喜欢
    • 2018-10-18
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多