Creating IOUSBHostDevice in Swift

How to instantiate IOUSBHostDevice in swift?

https://developer.apple.com/documentation/iousbhost/iousbhostdevice
references as the initializer:
https://developer.apple.com/documentation/iousbhost/iousbhostobject/3181717-initwithioservice

But when I call that init like:
let device = try IOUSBHostDevice(ioService: service, queue: queue)
I get the error:
init(ioService:queue:interestHandler:)' is unavailable in Swift: Please use the refined for Swift API
Seems there is no Swift init yet.

So you have to use in objC:
https://stackoverflow.com/questions/24002369/how-do-i-call-objective-c-code-from-swift
You should better check this initializer:
initWithIOService:options:queue:error:interestHandler:

When I tried to use it in Swift:
Code Block
let device = try IOUSBHostDevice(ioService: service, options: [], queue: queue)


Xcode has shown me a Fix It suggestion like this:
Code Block
let device = try IOUSBHostDevice(__ioService: service, options: [], queue: queue)

This compiles successfully.


But double-underscore-leaded identifiers are considered to be private, I wonder if you can use it safely.
This usually happens when refined-for-Swift version of the API was once planned, but the Swift version is not finished for some reason.

Some sort of inconsistency with IOUSBHostDevice and Swift runtime may cause an issue, or it may have just been forgotten.

Anyway, if you use this initializer in Swift, it's your own risk.
Creating IOUSBHostDevice in Swift
 
 
Q