我试图传递一个表示为launchArguments的字典的值,以便运行UI测试。
因此,我尝试将字典转换为String格式并像这样传递:
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。它也没有给予任何信息。有什么问题吗?
1条答案
按热度按时间0md85ypi1#
launchArguments是字符串数组:https://developer.apple.com/documentation/xctest/xcuiapplication/1500477-launcharguments
launchEnvironment是一个字典:https://developer.apple.com/documentation/xctest/xcuiapplication/1500427-launchenvironment
您可以访问launchEnvironment键:ProcessInfo.processInfo.environment[“yourKey”]