如何使用 Bool 类型定义变量(全局 - 结构)xcode8-swift3

How to define variable with type of Bool ( Globals - struct ) xcode8-swift3

我在 swift 文件中编写了以下代码:

import Foundation

struct globals {

    static var test = "someString"
    static var isContentLoadedFor1Events : Bool = false
    static var isContentLoadedFor2Events : Bool = false
    static var isContentLoadedFor3events : Bool = false
    static var isContentLoadedFor4Events : Bool = false

}

在行代码中(localMemory 是 UserDefaults.standard):

localMemory.setObject( true , forKey: globals.isContentLoadedFor1Events  )

Cannot convert value of type 'Bool' to expected argument type 'String'

像这样将 var 类型更改为 String -

import Foundation

struct globals {

    static var isContentLoadedFor1Events : String = "isContentLoadedFor1Events"

}

然后像这样保存-

localMemory.setObject( true , forKey: globals.isContentLoadedFor1Events )