Swift无法直接从其他视图控制器推断枚举类型

问题描述 投票:0回答:1

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

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
   }
  }

如果我像func showAnimation(_ animation: Animation)那样声明,它在Utitlity的第二个功能中会引发错误“使用未声明的标识符动画”

即使我没有提到课堂,但在第二种方法却没有,为什么在第一种方法中起作用?

ios xcode enums xcode10 swift4.2
1个回答
0
投票

FYI: addConfiguration也给我错误。

Error

请检查您的源代码Configurations类是在您的项目中定义的。

就是这样

© www.soinside.com 2019 - 2024. All rights reserved.