gpt4 book ai didi

Swift 嵌套结构访问

转载 作者:搜寻专家 更新时间:2023-11-01 05:59:31 25 4
gpt4 key购买 nike

我有以下嵌套结构:

public struct Session {
public enum Type: Int {
FirstLaunch = 0, NotRegistered, LoggedOut, LoggedIn
}
}

它非常简单,非常准系统。但是,当我尝试访问 FirstLaunch 时,Xcode 会抛出以下错误:

'Session.Type.Type' does not have a member named 'FirstLaunch'

有人知道发生了什么事吗?

最佳答案

Type 是 Swift 中的保留字。您可以通过用反引号包围它来转义它。

“If you need to give a constant or variable the same name as a reserved Swift keyword, you can do so by surrounding the keyword with back ticks (`) when using it as a name. However, you should avoid using keywords as names unless you have absolutely no choice.”

摘自:Apple Inc.“The Swift Programming Language”。电子书。 https://itun.es/us/jEUH0.l

关于Swift 嵌套结构访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25346112/

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