枚举原始值为AnyClass [英] Enum rawvalue as AnyClass

查看:203
本文介绍了枚举原始值为AnyClass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你可以给枚举是String或Intect的原始值,但是有一种方法使其类型像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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆