title: Swift bluetooth le, write message and wait for response
body: <p>Application can currently write a message,</p>
  
  <pre><code>// Write call 
  peripheral.writeValue(messageToData, for: charac, type: .withResponse)
  
  // Which calls
  public func peripheral(_ peripheral: CBPeripheral, didWriteValueFor 
  characteristic: CBCharacteristic, error: Error?) {
      if error != nil {
          print("messagesent")
      }
  }
  </code></pre>
  
  <p>Also when the characteristic has been set up for the peripheral I've set the notification to true</p>
  
  <pre><code>peripheral.setNotifyValue(true, for: characteristic)
  </code></pre>
  
  <p>When I sent a write message I get a response from the bluetooth device going "OK" or "ERR" which is triggered through the didUpdateValueFor peripheral delegate method.</p>
  
  <p>So the app can write and read responses from my device. However I want to be able to create a function that write the message and wait or checks for a response that is "OK" or "ERR". All the CORE BLuetooth functions can use my own protocol delegates if required.</p>
  
  <p>I've been looking at something like:</p>
  
  <pre><code>func writeAndCheckResponse(message: String){
  // Write to device
  bluetooth.writeToPeripheral(message: "Test", peripheral: bluetooth.connectedDevice!, writeCharacteristic: bluetooth.characteristic!)
  // need to add a way to check whether a notification has been recevied and that the message has been written
  }
  </code></pre>
  
  <p>I've thought about using callback closures or DispatchGroup but since the swift Bluetooth is asynchronous I'm not exactly sure how to carry this out.</p>