gpt4 book ai didi

ios - 如果让 - 多个条件

转载 作者:搜寻专家 更新时间:2023-10-31 22:32:53 25 4
gpt4 key购买 nike

我可以在 IF 中使用 let obj = something 的多个条件吗

if let u = custom["u"] as? String || let url = custom["URL"] as? String
{
// Do something here
}

最佳答案

您可以添加多个条件,但前提是您使用 AND 条件。

如果您使用OR,您不知道哪个值设置正确,因此无法正确访问变量。

通过 AND 测试,您可以确定这两个变量都已正确创建,因此您可以确定它们的类型。

你必须编写用逗号分隔的测试:

if let u = custom["u"], 
let url = custom["URL"] {
// Do something here
}

此外,您还可以在 if let block 之后直接添加一些条件,使用 where 关键字:

if let u = custom["u"] where u == "testValue", 
let url = custom["URL"] {
// Do something here
}

关于ios - 如果让 - 多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36172373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com