title: iOS Swift BLE: Discovering Multiple Characteristics within a Single Service
body: <p>So I am following this iOS App code example from <a href="http://www.raywenderlich.com/85900/arduino-tutorial-integrating-bluetooth-le-ios-swift" rel="nofollow">http://www.raywenderlich.com/85900/arduino-tutorial-integrating-bluetooth-le-ios-swift</a> </p>
  
  <p>The code below, taken from the link above, registers one characteristic with the service. How would you register multiple characteristics for one service so that they can be read and written to, using Swift? </p>
  
  <pre><code>/* Services &amp; Characteristics UUIDs */
  let BLEServiceUUID = CBUUID(string: "025A7775-49AA-42BD-BBDB-E2AE77782966")
  let PositionCharUUID = CBUUID(string: "F38A2C23-BC54-40FC-BED0-60EDDA139F47")
  let BLEServiceChangedStatusNotification = "kBLEServiceChangedStatusNotification"
  .
  .
  .
  .
  .
  func peripheral(peripheral: CBPeripheral!, didDiscoverServices error: NSError!) {
    let uuidsForBTService: [CBUUID] = [PositionCharUUID]
  
    if (peripheral != self.peripheral) {
      // Wrong Peripheral
      return
    }
  
    if (error != nil) {
      return
    }
  
    if ((peripheral.services == nil) || (peripheral.services.count == 0)) {
      // No Services
      return
    }
  
    for service in peripheral.services {
      if service.UUID == BLEServiceUUID {
        peripheral.discoverCharacteristics(uuidsForBTService, forService: service as CBService)
      }
    }
  }
  
  func peripheral(peripheral: CBPeripheral!, didDiscoverCharacteristicsForService service: CBService!, error: NSError!) {
    if (peripheral != self.peripheral) {
      // Wrong Peripheral
      return
    }
  
    if (error != nil) {
      return
    }
  
    for characteristic in service.characteristics {
      if characteristic.UUID == PositionCharUUID {
        self.positionCharacteristic = (characteristic as CBCharacteristic)
        peripheral.setNotifyValue(true, forCharacteristic: characteristic as CBCharacteristic)
  
        // Send notification that Bluetooth is connected and all required characteristics are discovered
        self.sendBTServiceNotificationWithIsBluetoothConnected(true)
      }
    }
  </code></pre>
  
  <p>Thanks in advance!</p>