gpt4 book ai didi

Swift:如何在条件绑定(bind)上使用多个 'where'?

转载 作者:行者123 更新时间:2023-11-28 10:20:34 24 4
gpt4 key购买 nike

我做了一些谷歌搜索,示例使用“,”来使用多个 where 语句,但它对我不起作用。我也试过&&。

if let movesDict = pokemonInfoDict["moves"] as? [Dictionary<String,AnyObject>] where movesDict.count > 0, movesDict["learn_type"] == "level up"{
}

if let movesDict = pokemonInfoDict["moves"] as? [Dictionary<String,AnyObject>] where movesDict.count > 0 && movesDict["learn_type"] == "level up"{
}

如有任何帮助,我们将不胜感激。

最佳答案

你想要 && - 你的代码一定有其他问题,因为它有效:

let foo: Int? = 10

if let bar = foo where bar > 8 && bar % 2 == 0 {
print("It works")
}

关于Swift:如何在条件绑定(bind)上使用多个 'where'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35678976/

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