如果问题与外围设备
问题描述:
循环我正在使用外围设备扫描仪,我有问题,如果循环。 我收到错误:“for语句中的预期条件”和“Braced语句块是未使用的结束语”。这是这个循环:如果问题与外围设备
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> {
}
,而不是你想要的:
func peripheral(peripheral: CBPeripheral!, didDiscoverServices error: NSError!)
{
if let servicePeripherals = peripheral.services as? [CBService]
{
for servicePeripheral in servicePeripherals
{
println("\(servicePeripheral)")
}
}
}
:
for <new variable> in <some collection> {
}
也许你在[CBService]
(阵列的CBService
)意味着环