将struct ProcessSerialNumber转换为UnsafePointer <void> </void>

时间:2015-02-19 15:22:43

标签: macos cocoa swift

我有ProcessSerialNumber并希望从中创建NSAppleEventDescriptor,方法与issue 14 of objc.io中显示的相同。但是构造函数需要UnsafePointer<Void>

let psn = ProcessSerialNumber(highLongOfPSN: UInt32(0), lowLongOfPSN: UInt32(kCurrentProcess))

let target = NSAppleEventDescriptor(
                 descriptorType: typeProcessSerialNumber,
                 bytes: &psn, // <-- this fails
                 length: sizeof(ProcessSerialNumber)
             )

我错过了正确转换它的内容吗?

1 个答案:

答案 0 :(得分:4)

另一个光荣的快速错误消息失败,真正的问题是typeProcessSerialNumber是一个Int,初始化程序需要一个DescType。使用:

let target = NSAppleEventDescriptor(descriptorType: DescType(typeProcessSerialNumber), bytes:&psn, length:sizeof(ProcessSerialNumber))