swift enum

2022-11-22  本文已影响0人  f8d1cf28626a

swift nuem

高级使用

链表

indirect enum List{
    case end
    case node(elment: Any,next: List)
}


var map = List.node(elment: 10, next: List.node(elment: "HB", next: List.end))

var conf = true

while(conf) {
    if case List.node(let element, let nex) = map {
        print("true  \(element)")
        print("true  \(nex)")
        map = nex
        if case List.end = nex {
            conf = false
            print("false  \(nex)")
        }
    }
}

print("end")
HB

超高级使用(模拟网络请求产生依赖)

indirect enum ManagerNet {
    static func getNet1() ->Self.Type{
         print("data1")
        return self
    }
    static func getNet2() ->Self.Type{
        print("data2")
        return self
    }
    static func getNet3() ->Self.Type{
        print("data3")
        return self
    }
    static func getNet4(data:Any) ->Self.Type{
        print(data)
        return self
    }
    case node(_ netFunc:Self)
    case end
}


print(MemoryLayout<ManagerNet>.stride) // 8
print(MemoryLayout<ManagerNet>.size) // 8

DispatchQueue.global().async {
    // 超高级用法(依赖执行)
    _ = ManagerNet.node(.getNet1().getNet2().getNet4(data: "HB").getNet3().end)
}
BH
上一篇 下一篇

猜你喜欢

热点阅读