【发布时间】:2018-12-15 15:44:07
【问题描述】:
我有一个 if 语句,用于检查数组元素是否与局部变量匹配。
if pinArray.contains(where: {$0.title == restaurantName})
如何创建这个元素的变量? 我试过了
let thePin = pinArray.contains(where: {$0.title == restaurantName})
但这带有“无法将布尔值转换为 MKAnnotation”。
我也尝试了
的变体let pins = [pinArray.indexPath.row]
let pinn = pins(where: pin.title == restaurantName) (or close to it)
mapp.selectAnnotation(thePin as! MKAnnotation, animated: true)
无济于事。我缺少什么基本步骤?
【问题讨论】:
-
如果你真的有
if pinArray.contains(where: {$0.title == restaurantName}) { // some stuff }这样的代码,那么你绝对可以用let thePin = pinArray.contains(where: {$0.title == restaurantName})替换它,然后是if thePin { // some stuff }。 -
是否在更新中看到任何导致信号 sibart 的内容?
-
请勿发布代码图片。以文本形式发布代码。
-
您为什么要强制将
Bool强制转换为MKAnnotation?thePin是一个Bool,表示数组是否包含该值。 -
我试图创建一个等于 pinArray 的 pin 的变量,该 pinArray 等于/具有与 restaurantName 相同的标题。
标签: swift if-statement var