title: How to wait until delegate method is called?
body: <p>I want to create a method <code>startCentralManager</code> that waits until the delegate method <code>centralManagerDidUpdateState</code> is called and returns a boolean value depending on the central state.</p>
  
  <p>I want to use the method like this:</p>
  
  <pre><code>let centralManager = CentralManager()
  let ready = centralManager.startCentralManager()
  </code></pre>
  
  <p>The CentralManager class should look something like this</p>
  
  <pre><code>class CentralManager: NSObject, CBCentralManagerDelegate {
     var centralManager: CBCentralManager?
  
     func startCentralManager() -&gt; Bool {
        centralManager = CBCentralManager.init(delegate: self, queue: nil)
     }
  
     func centralManagerDidUpdateState(central: CBCentralManager) {
        // startCentralManager() should return this
        return central.state == CBCentralManagerState.PoweredOn
     }
  }
  </code></pre>
  
  <p>How can I solve this?</p>
  
  <p>Thank you very much, in advance.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>There are some other methods, but the situation is almost equal. Another method is the following:</p>
  
  <pre><code>let connected = centralManager.connect&lt;PARAMS&gt;)
  </code></pre>
  
  <p>In this method if have to call</p>
  
  <pre><code>func scanForPeripheralsWithServices(_ serviceUUIDs: [CBUUID]?, options options: [String : AnyObject]?)
  </code></pre>
  
  <p>and wait until the delegate method</p>
  
  <pre><code>func centralManager(_ central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData advertisementData: [String : AnyObject], RSSI RSSI: NSNumber)
  </code></pre>
  
  <p>is called. Here, I have to call</p>
  
  <pre><code>func connectPeripheral(_ peripheral: CBPeripheral, options options: [String : AnyObject]?)
  </code></pre>
  
  <p>and again wait until the delegate method</p>
  
  <pre><code>func centralManager(_ central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral)
  </code></pre>
  
  <p>is called. In case of success, the call to <code>centralManager.connect(&lt;PARAMS&gt;)</code> should return <code>true</code>.</p>