gpt4 book ai didi

ios - 即使条件为假,代码也会执行

转载 作者:行者123 更新时间:2023-11-28 06:37:21 25 4
gpt4 key购买 nike

我对 if let where 有问题,即使 where 条件为假,大括号内的代码也会执行

   if let child = value["child"]  where child[0]["src"] != nil {
print("Thank you :3")
continue
}

child[0]["src"] 为 nil

编辑

我通过添加另一个 let 解决了问题,但仍然不明白为什么上面的代码不起作用。

   if let child = value["child"] ,let src = child[0]["src"] where src != nil {
let imglink = src as! String;
self.content.append(NSURL(string: imglink)!);
continue
}

最佳答案

去掉where元素,你可以像下面这样进行多重检查

if let child = value["child"] , source = child[0]["src"] {
print("Thank you :3")
print("\(child) - \(source)")
continue
}

关于ios - 即使条件为假,代码也会执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38843658/

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