Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在 Xcode 的 Swift Cocoa 应用程序中使用全局常量。我的问题是,我在哪里写声明?我使用什么样的文件?
创建一个名为的新文件Global.swift并定义一个结构,其中静态成员是避免污染命名空间所需的常量:
Global.swift
// Global.swift private struct MyConstants { static let c1 = 1 static let c2 = 2 }
private表示该结构是当前模块的本地结构。当您需要引用常量时:
private
let x = MyConstants.c1