将字段添加到Swift中的枚举 [英] Add field to enum in Swift

查看:119
本文介绍了将字段添加到Swift中的枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理Swift中的枚举和子类化。
每个孩子都带有自己的新属性,这些属性必须存储在枚举中。这个枚举在母班中被宣布为一些价值观。我想为此枚举添加一些值。我无法找到如何做到这一点,我没有尝试这个结果:

  extension MotherClass {
枚举枚举{
case NewProperty
}
}


解决方案

将项目添加到枚举中的唯一方法是将它们直接添加到其声明中。您不能通过继承或任何其他扩展机制将更多项目添加到枚举中:枚举必须在它的声明点。


I'm dealing with enum and subclassing in Swift. Each child bring its own new properties which have to be stored in an Enum. This enum is declared with some values in the mother class. I'd like to add some value to this enum. I can't find out how to do it, I tried this without result :

extension MotherClass {
    enum Enumeration {
        case NewProperty
    }
}

解决方案

The only way to add items to an enum is to add them directly to its declaration. You cannot add more items to an enum through inheritance or any other extension mechanism: the enum must be fully defined at the point of its declaration.

这篇关于将字段添加到Swift中的枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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