0

I have integrated Bluetooth Objective-C library and when it discovers devices, the device details are stored in the array of 'BGXDevice' - BGXArray (print from Xcode debugger below).

print(BGXArray)

[DEV-4F7D rssi=-85 id=673A4E30-01FA-7DB2-BBF3-F65916C8C05C DeviceState=Disconnected, DEV-4F7D rssi=-96 id=673A4E30-01FA-7DB2-BBF3-F65916C8C05C DeviceState=Disconnected]

How do I access the elements in this array e.g. id in Swift

print(BGXArray[0].id)

Gives in Xcode error value of type 'BGXDevice' has no member 'id'

I could do some string manipulation to find 'id' from the array element and then the value after '=' sign, but there must be a better way?

Jukka
  • 55
  • 3
  • It has a property `identifier` in Objective-C, are you looking for this: https://docs.silabs.com/gecko-os/1/bgxhost/framework/latest/sdk/ios/group-b-g-x-device#a8429ffdc556b0e508e07f9ed22e515f4 ? – Larme Apr 29 '22 at 22:30
  • device_unique_id on the above link is only accessible once the bluetooth device is connected. Before connecting to device after discovering the devices, the BLE stack returns 'BGXDevice' property that has in it [name rssi=xx id =yy DeviceState=Disconnected] and I was hoping to simply understand how to retrieve id=yy programmatically in order only append the [BGXArray] for a new device 'id'. I don't understand the format [name rssi=xx id=yy deviceState=x]. Is it a Dictionary? And how to then access it's elements. – Jukka Apr 30 '22 at 00:56
  • I guess it's just an override of `description`, see `CustomStringConvertible` or `description`. See https://stackoverflow.com/questions/2921049/objective-c-override-for-custom-objects etc. Edit: I've checked, it's there: https://github.com/SiliconLabs/wireless-xpress/blob/master/iOS/BGXpress/bgxpress/BGXDevice.m#L143 and the value printed is `self.identifier.UUIDString`, so that should be the one you want to read. – Larme Apr 30 '22 at 09:54

1 Answers1

0

According to the docs, to get the id you need to call something like this:

Obj-c code:

NSLog(BGXArray[0].identifier.uuidString)

The rest of the properties are listed here

The debugger output that you are seeing does not necessarily contain the actual property names of BGXDevice but simply a debug string that the authors chose.

Aris
  • 1,529
  • 9
  • 17