我在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 )
无法转换类型' Bool'预期参数类型'字符串'
答案 0 :(得分:1)
将var type更改为String -
import Foundation
struct globals {
static var isContentLoadedFor1Events : String = "isContentLoadedFor1Events"
}
并像这样保存 -
localMemory.setObject( true , forKey: globals.isContentLoadedFor1Events )