enum Things { case Thing1 case Thing2}let something:Any = Things.Thing1let mirror = Mirror(reflecting: something)if (mirror.displayStyle == .Enum) { print("Reflected type is Enum") // works}解决方法
enum Things { case Thing1 case Thing2}let something:Any = Things.Thing1something.dynamicType == Things.self // true
根据讨论更新..
protocol P {}enum Things:P { case Thing1 case Thing2}enum Things2:P{ case Things21}let something:Any = Things.Thing1something.dynamicType == Things.self // trueif let p = something as? P { print(true)}let somethingelse: Any = Things2.Things21if let p = somethingelse as? P { print(true)}总结
以上是内存溢出为你收集整理的如何在Swift中检查Enum类型?全部内容,希望文章能够帮你解决如何在Swift中检查Enum类型?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)