2014-09-01 70 views
0

循環我正在使用外圍設備掃描儀,我有問題,如果循環。 我收到錯誤:「for語句中的預期條件」和「Braced語句塊是未使用的結束語」。這是這個循環:如果問題與外圍設備

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

回答

1

您的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)意味着環