gpt4 book ai didi

ios - 如果外围设备出现问题则循环

转载 作者:行者123 更新时间:2023-11-29 02:42:20 24 4
gpt4 key购买 nike

我正在处理外设扫描仪,但我遇到了 if 循环问题。我收到错误:“for 语句中的预期条件”和“语句的支撑 block 是未使用的闭包”。这是这个循环:

func peripheral(peripheral: CBPeripheral!, didDiscoverServices error: NSError!)
{
if let servicePeripheral = peripheral.services as? [CBService]
{
for peripheral.services in CBService
{
println("\(servicePeripheral)")
}
}
}

最佳答案

您的 for 循环格式不正确。你有:

for <some existing value> in <a data type> {
}

相反你想要:

for <new variable> in <some collection> {
}

也许您打算遍历 [CBService](CBService 的数组):

func peripheral(peripheral: CBPeripheral!, didDiscoverServices error: NSError!)
{
if let servicePeripherals = peripheral.services as? [CBService]
{
for servicePeripheral in servicePeripherals
{
println("\(servicePeripheral)")
}
}
}

关于ios - 如果外围设备出现问题则循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25603209/

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