枚举原始值为AnyClass [英] Enum rawvalue as AnyClass
问题描述
枚举名称:AnyClass {
case classOne = ClassOne
case classTwo = ClassTwo
}
ClassOne和ClassTwo是类。我得到的错误是:
原始类型AnyClass不能从任何文字
还有另一种方式来实现这一点?
那么还有另一种方式来实现这一点?
我不知道这是什么,但就Swift语法而言,规则是直截了当的。这个:
枚举名称:AnyClass {
是非法的。只允许使用String和Int作为原始值类型(只允许使用String和Int文字作为案例值)。
I know you can give enum's the rawvalue of String or Int ect but is there a way to make its type like AnyClass for example
enum Name:AnyClass{
case classOne = ClassOne
case classTwo = ClassTwo
}
Where ClassOne and ClassTwo are classes. The error I get is:
Raw type 'AnyClass' is not convertable from any literal
So is there another way to achieve this?
So is there another way to achieve this?
I do not know what "this" is, but as far as Swift syntax is concerned, the rule is straightforward. This:
enum Name:AnyClass {
is illegal. Only String and Int are allowed as raw value types (and only String and Int literals are allowed as case values).
这篇关于枚举原始值为AnyClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!