title: Error: Simultaneous accesses to 0x100e0b108, but modification requires exclusive access
body: <p>I am working on a Bluetooth chat app using CoreBluetooth.</p>
  <pre><code>func updateAdvertisingData() {
      
      if (peripheralManager.isAdvertising) {
          peripheralManager.stopAdvertising()
      }
      
      let userData = UserData()
      let advertisementData = String(format: &quot;%@&quot;, userData.name)          peripheralManager.startAdvertising([CBAdvertisementDataServiceUUIDsKey:[WR_UUID], CBAdvertisementDataLocalNameKey: advertisementData])
  }
  
  func addOrUpdatePeripheralList(device: Device, list: inout Array&lt;Device&gt;) {
  
      if !list.contains(where: { $0.peripheral.identifier == device.peripheral.identifier }) {
          
          list.append(device)
          tableView.reloadData()
      }
      else if list.contains(where: { $0.peripheral.identifier == device.peripheral.identifier
          &amp;&amp; $0.name == &quot;unknown&quot;}) &amp;&amp; device.name != &quot;unknown&quot; {
          
          for index in 0..&lt;list.count {
              
              if (list[index].peripheral.identifier == device.peripheral.identifier) {
                  
                  list[index].name = device.name
                  break
              }
          }
          tableView.reloadData()
      }}}
      extension ViewController: UITableViewDataSource {
              func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
                  
                  print(visibleDevices.count)
                  return visibleDevices.count
                 
              }
      
  extension ViewController: CBCentralManagerDelegate {
          func centralManagerDidUpdateState(_ central: CBCentralManager) {
              if central.state == .poweredOn {
                  
                  self.centralManager.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])
          }}
  
          func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
              var peripheralName = cachedPeripheralNames[peripheral.identifier.description] ?? &quot;unknown&quot;
              
              if let advertisementName = advertisementData[CBAdvertisementDataLocalNameKey] as? String {
                  
                  peripheralName = advertisementName
                  cachedPeripheralNames[peripheral.identifier.description] = peripheralName
              }
              
              let device = Device(peripheral: peripheral, name: peripheralName)
              
              self.addOrUpdatePeripheralList(device: device, list: &amp;visibleDevices)
              self.addOrUpdatePeripheralList(device: device, list: &amp;cachedDevices)
           }
          func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
              peripheral.delegate = self
              peripheral.discoverServices(nil) }} 
      extension ViewController: CBPeripheralManagerDelegate {
          func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
              
              if (peripheral.state == .poweredOn) {
                  print(&quot;peripheralManagerDidUpdateState&quot;)
                  
                  updateAdvertisingData()}}
  </code></pre>
  <p>I have added the code also now. Here I am getting <em><strong>Simultaneous accesses to 0x100e0b108, but modification requires an exclusive access</strong></em> error on the return statement. I am using swift 5, development target is iOS 12.4.</p>
  <p>Here the device will act both as a peripheral and a central.</p>