title: iOS Eddystone beacon - Issue in finding NamespaceID
body: <p>I have one old project in Objective - C. I need to convert that in latest Swift - 5.
  Everything is working fine except Eddystone beacons detection.</p>
  
  <p><strong>Old Objective C code,</strong></p>
  
  <pre><code>-(NSString *) findNameSpace : (id) beaconInfo {
  
      ESSBeaconInfo *beacon = beaconInfo;
      ESSBeaconID *Bid = beacon.beaconID;
      NSLog(@"Beacon : %@", beacon);
      NSLog(@"Beacon ID Length : %lu",(unsigned long)Bid.beaconID.length);
      if (Bid.beaconID.length == 16) {
          NSData *d1 = [Bid.beaconID subdataWithRange:NSMakeRange(0, 10)];
          NSLog(@"Sub Data : %@", d1);
          NSString *namespace = [[NSString stringWithFormat:@"%@",d1] stringByReplacingOccurrencesOfString:@"&lt;" withString:@""];
          namespace = [namespace stringByReplacingOccurrencesOfString:@"&gt;" withString:@""];
          namespace = [namespace stringByReplacingOccurrencesOfString:@" " withString:@""];
          NSLog(@"namespace : %@", namespace);
          return namespace;
      }
  
      return @"";
  }
  </code></pre>
  
  <p><strong>Output:-</strong></p>
  
  <p>Beacon : Eddystone, id: ESSBeaconID: beaconID= <a href="https://i.stack.imgur.com/npfpE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/npfpE.png" alt="enter image description here"></a>, RSSI: -65, txPower: -31</p>
  
  <p>Beacon ID Length: 16</p>
  
  <p>Sub Data: <a href="https://i.stack.imgur.com/MtLAc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MtLAc.png" alt="enter image description here"></a></p>
  
  <p>namespace : a457ae5727fa30f48dc9</p>
  
  <p><strong>My Swift Code,</strong></p>
  
  <pre><code>func findNameSpace(_ beaconInfo: Any) -&gt; String? {
          let beacon: ESSBeaconInfo = beaconInfo as! ESSBeaconInfo
          let Bid: ESSBeaconID = beacon.beaconID
          print("Beacon : \(beacon)")
          print("Beacon ID Length : \(Bid.beaconID.count)")
          if Bid.beaconID.count == 16 {
              let d1 = Bid.beaconID.subdata(in: Range(NSRange(location: 0, length: 10))!)
              print("Sub Data : \(d1)")
              var namespace: String? = nil
              namespace = "\(d1)".replacingOccurrences(of: "&lt;", with: "")
              namespace = namespace?.replacingOccurrences(of: "&gt;", with: "")
              namespace = namespace?.replacingOccurrences(of: " ", with: "")
              print("namespace : \(namespace ?? "")")
              return namespace
          }
          return ""
      }
  </code></pre>
  
  <p><strong>Output:-</strong></p>
  
  <p>Beacon : Eddystone, id: ESSBeaconID: beaconID=<a href="https://i.stack.imgur.com/npfpE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/npfpE.png" alt="enter image description here"></a>, RSSI: -51, txPower: -31</p>
  
  <p>Beacon ID Length: 16</p>
  
  <p>Sub Data: 10 bytes</p>
  
  <p>namespace : 10bytes</p>
  
  <p>========================================</p>
  
  <p>I am facing issue with getting namespace.. beacause you can see from above output. Data is converting in bytes in my Swift Code. I don't have any idea how to handle it. 
  Objective C code is working perfectly fine.
  Any help is appreciated! Thank you.</p>