我在外围扫描仪上工作,我遇到if循环问题。 我得到错误:"陈述中的预期条件"和#34;声明的声明块是一个未使用的闭包"。这就是这个循环:
func peripheral(peripheral: CBPeripheral!, didDiscoverServices error: NSError!)
{
if let servicePeripheral = peripheral.services as? [CBService]
{
for peripheral.services in CBService
{
println("\(servicePeripheral)")
}
}
}
答案 0 :(得分:1)
您的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)")
}
}
}