如果周边问题循环

时间:2014-09-01 09:55:27

标签: ios swift bluetooth-lowenergy

我在外围扫描仪上工作,我遇到if循环问题。 我得到错误:"陈述中的预期条件"和#34;声明的声明块是一个未使用的闭包"。这就是这个循环:

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

1 个答案:

答案 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)")
        }
    }
}