swift enum与计算值swift

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift enum与计算值swift相关的知识,希望对你有一定的参考价值。

//playground to test automata

enum dualStorage {
    case A(int:Int, string:String)
    
    init(int:Int, string:String){
        self = dualStorage.A(int: int, string: string)
    }
    //computed property for the int
    var int:Int {
        switch self {
        case .A(let int, _):
            return int
        }
    }
    //computed property for the string
    var string:String {
        switch self {
        case .A(_, let string):
            return string
        }
    }
    
}

以上是关于swift enum与计算值swift的主要内容,如果未能解决你的问题,请参考以下文章