我正在尝试传递一个表示为 launchArguments 字典的值,以便运行 UI 测试。
所以,我尝试将字典转换为字符串格式并像这样传递它:
let dic = ["Key1": "Value1", "Key2": "Value2"]
do {
let data = try JSONEncoder().encode(dic)
if let value = String(data: data, encoding: .utf8) {
launchArguments += [ "-launchKey", value ]
}
} catch {
print("Error encoding launchArguments: \(error.localizedDescription)")
}
当应用程序启动时,它不会向 UserDefaults 添加字典。它也不提供任何信息。可能有什么问题?
launchArguments 是字符串数组: https://developer.apple.com/documentation/xctest/xcuiaapplication/1500477-launcharguments
launchEnvironment 是一个字典: https://developer.apple.com/documentation/xctest/xcuiaapplication/1500427-launchenvironment
您可以访问 launchEnvironment 密钥: ProcessInfo.processInfo.environment["yourKey"]