2014-09-01 2 views
0

주변 장치 스캐너에서 작동 중이며 if 루프에 문제가 있습니다. "for 문에서 예상 된 조건"및 "명령문의 중괄호 블록이 사용되지 않는 폐쇄입니다."라는 오류가 발생합니다. 이 루프는 다음과 같습니다.루프가 주변 장치와 문제가있는 경우

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의 배열)을 통해 루프 의미