Xcode 绝对时间类型未导入Swift

Xcode 绝对时间类型未导入Swift,xcode,swift,types,compiler-errors,iokit,Xcode,Swift,Types,Compiler Errors,Iokit,Swift编译器在尝试为IOKit HID代码使用AbsoluteTime类型时似乎非常困惑 此块编译并运行良好,打印“UnsignedWide” 然而,这并不编译 let time1: AbsoluteTime = event.timestamp "error: use of undeclared type 'AbsoluteTime'" let wide1: UnsignedWide = event.timestamp "error: use of undeclared type 'U

Swift编译器在尝试为IOKit HID代码使用AbsoluteTime类型时似乎非常困惑

此块编译并运行良好,打印“UnsignedWide”

然而,这并不编译

let time1: AbsoluteTime = event.timestamp

"error: use of undeclared type 'AbsoluteTime'"
let wide1: UnsignedWide = event.timestamp

"error: use of undeclared type 'UnsignedWide'"
这也不会编译

let time1: AbsoluteTime = event.timestamp

"error: use of undeclared type 'AbsoluteTime'"
let wide1: UnsignedWide = event.timestamp

"error: use of undeclared type 'UnsignedWide'"
这也无法编译,但这是意料之中的

let uint: UInt64 = event.timestamp

"error: cannot convert value of type 'AbsoluteTime' (aka 'UnsignedWide') to specified type 'UInt64'"
因此,既然Swift清楚地知道UnsignedWide是一个具有两个UInt32字段的结构,我想我应该尝试用这些特性定义自己的结构,但这也失败了

struct UnsignedWide {
    let lo: UInt32
    let hi: UInt32
}
typealias AbsoluteTime = UnsignedWide
let time2: AbsoluteTime = event.timestamp
let wide2: UnsignedWide = event.timestamp

"error: cannot convert value of type 'AbsoluteTime' (aka 'UnsignedWide') to specified type 'AbsoluteTime' (aka 'UnsignedWide')" 
"error: cannot convert value of type 'AbsoluteTime' (aka 'UnsignedWide') to specified type 'UnsignedWide'"
至少这是可行的

let time3: AbsoluteTime = unsafeBitCast(event.timestamp, AbsoluteTime.self)
但我不想这样做,我只能用这种丑陋的方式创建绝对时间变量

let AbsoluteTime = event.timestamp.dynamicType
let time4 = AbsoluteTime.init(lo: lo, hi: hi)
不幸的是,这不允许我使用AbsoluteTime作为函数或结构或类似的类型,所以这并不能真正解决我的问题

Xcode 7.3和Xcode 7.3.1 GM就是这种情况


有人知道解决方案吗?

使用
Darwin.UnsignedWide
,它的别名是
AbsoluteTime

例如:

这包括:

import Darwin

public protocol CurrentAbsoluteTimeProvider: class {
    func currentAbsoluteTime() -> Darwin.AbsoluteTime
}
这无法编译:

import Darwin

public protocol CurrentAbsoluteTimeProvider: class {
    func currentAbsoluteTime() -> AbsoluteTime
}
我已将此文件添加到使用IOKit的库中:


顺便说一下,我们公司正在开发一个Swift库,用于使用IOKit。Permalink:

使用
Darwin.UnsignedWide
,其别名为
AbsoluteTime

例如:

这包括:

import Darwin

public protocol CurrentAbsoluteTimeProvider: class {
    func currentAbsoluteTime() -> Darwin.AbsoluteTime
}
这无法编译:

import Darwin

public protocol CurrentAbsoluteTimeProvider: class {
    func currentAbsoluteTime() -> AbsoluteTime
}
我已将此文件添加到使用IOKit的库中:


顺便说一下,我们公司正在开发一个Swift库,用于使用IOKit。Permalink:

对我来说像个虫子。对我来说像个虫子。