gpt4 book ai didi

swift - 为什么 Apple 的枚举类型的打印方式与 Swift 的不同?

转载 作者:行者123 更新时间:2023-11-28 10:27:13 27 4
gpt4 key购买 nike

<分区>

似乎当您从 macOS SDK(可能还有其他)打印()枚举类型时,它会打印出类型名称,但是当您从您自己的枚举打印时,它会打印出案例名称。

在下面的示例中,我希望看到“安全案例:wpaPersonalMixed”而不是“安全案例:CWSecurity”。

有什么技巧可以使它正常工作吗?

import CoreWLAN

// Working example
enum Numbers: Int {
case one = 1
}
print("number case: \(Numbers.one)") // "number case: one" <-- EXPECTED
print("number raw: \(Numbers.one.rawValue)") // "number raw: 1"

// Failing example
let wifiClient: CWWiFiClient = CWWiFiClient()
let interface: CWInterface = wifiClient.interface(withName: "en0")! // interface name is specific to my machine. YMMV
let security: CWSecurity = interface.security()
print("security case: \(security)") // "security case: CWSecurity" <-- PROBLEM
print("security raw: \(security.rawValue)") // "security raw: 3"

swift 5.1macOS SDK 10.4

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com