title: CoreBluetooth XPC connection invalid
body: <pre><code>public class BLE: NSObject, CBCentralManagerDelegate {
  
      var centralManager:CBCentralManager!
  
      public override init() {
          super.init()
          self.centralManager = CBCentralManager.init(delegate: self, queue: nil)
      }
  
      public func centralManagerDidUpdateState(_ central: CBCentralManager) {
  
          switch central.state {
          case .unknown:
              print("unknown")
          case .resetting:
              print("resetting")
          case .unsupported:
              print("unsupported")
          case .unauthorized:
              print("unauthorized")
          case .poweredOff:
              print("powered off")
          case .poweredOn:
              print("powered on")
              self.centralManager.scanForPeripherals(withServices: nil, options: nil)
          }
      }
  }
  </code></pre>
  
  <p>This is my code, whenever I run it, it gives me the message </p>
  
  <blockquote>
    <p>“[CoreBlueooth] XPC Connection Invalid”</p>
  </blockquote>
  
  <p>I did try adding <strong>NSBluetoothPeripheralUsageDescription</strong> into my info.plist file but that didn’t work. </p>
  
  <p>The weird part though is that, if I initialize <strong>CBCentralManager</strong> directly instead of using a class then everything works fine. </p>
  
  <p>This problem only arises when I try to initialize <strong>CBCentralManager</strong> by creating on object of the class <strong>BLE</strong> or any other class for that matter.</p>