swift - IOHIDDeviceSetReport 方法不接受 Swift 3 中的 UnsafeRawPointer 类型

标签 swift xcode swift3

IOHIDDeviceSetReport 方法不接受 UnsafeRawPointer 类型 方法签名是:

IOHIDDeviceSetReport(<#T##device: IOHIDDevice##IOHIDDevice#>, <#T##reportType: IOHIDReportType##IOHIDReportType#>, <#T##reportID: CFIndex##CFIndex#>, <#T##report: UnsafePointer<UInt8>##UnsafePointer<UInt8>#>, <#T##reportLength: CFIndex##CFIndex#>)

thta 只允许将 UnsafePointer 类型作为输入,但在 swift 3 中我只能使用 UnsafeRawPointer 类型。 有人知道如何从 UnsafeRawPointer 获取 UnsafeRawPointer 吗?

最佳答案

有几种方法可以将 UnsafeRawPointer 迁移到 UnsafePointer。我用得最多的是:

UnsafePointer.withMemoryRebound(to:capacity:_)

您应该能够使用上述方法或下一页中提到的其他方法之一来完成您需要的操作:

https://swift.org/migration-guide/se-0107-migrate.html

关于swift - IOHIDDeviceSetReport 方法不接受 Swift 3 中的 UnsafeRawPointer 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40340037/

相关文章:

swift3 - XCode 8 使用 Pod 创建框架

ios - UICollectionViewCell 的动态高度

swift - 如何将值从 JSON 添加到模型,在我下面的代码中

ios - 检测在 `View` 上点击了哪个 `Cell`

ios - AFNetworking 更改重定向请求从 GET 到 POST

ios - 如何仅上传 iMessage Sticker 应用程序?

ios - 使用 float 抽屉交换中心 View Controller

swift 3 : How to retry Firebase upload on failure

xcode - 如何在 Swift 代码 (1.2) 中抑制弃用警告?

ios - 如何在 Swift 中使用字典构建 URL