macOS / Swift 4 - CBPeripheral.identifer only available in 10.13

I'm trying to get my macOS project all updated for Swift 4, but I'm running into a problem trying to reference CBPeripheral.identifier. It looks like, as of Swift 4, this property is now attributed with "@available(OSX 10.13, *)" (it's actually from the CBPeer protocol). I can no longer target earlier versions of macOS when using `identifier`, and I can find no suitable replacement for using identifier. It looks like this has been the case since Xcode 9 was released, so I'm wondering if this change is intentional?


Ironically, the documentation still seems to show that `identifier` is the correct mechanism for differentiating peripherals:

"The

CBPeripheral
class represents remote peripheral devices that your app—by means of a central manager (an instance of
CBCentralManager
)—has discovered advertising or is currently connected to. Peripherals are identified by universally unique identifiers (UUIDs), represented by
NSUUID
objects. Peripherals may contain one or more services or provide useful information about their connected signal strength."


Any advice on what I should be using if I want to target 10.12, but build with Swift 4?

Accepted Reply

Seems to be a bug of macOS SDK 10.13. Better send a bug report soon.


Until this issue will be fixed, can't you use this sort of workaround?

peripheral.value(forKey: "identifier") as! NSUUID as UUID

Replies

Seems to be a bug of macOS SDK 10.13. Better send a bug report soon.


Until this issue will be fixed, can't you use this sort of workaround?

peripheral.value(forKey: "identifier") as! NSUUID as UUID

Hey OOPer,


Thanks for the workaround, that works great. I tend to forget most of Apple's SDKs support KVO. Now I just need to make sure to remember to clean that up around release time.


Now that you've confirmed it isn't just my going crazy, I've submitted the bug report too :-) Hopefully it gets fixed before the gold master is locked down!

Still not fixed in Xcode 9.3.