此代码用于从位数组构建位模式,在Xcode 9中给我错误(适用于8.3.3(
@_specialize(UInt8)
func integerFrom<T: UnsignedInteger>(_ bits: Array<Bit>) -> T {
var bitPattern: T = 0
for idx in bits.indices {
if bits[idx] == Bit.one {
let bit = T(UIntMax(1) << UIntMax(idx))
bitPattern = bitPattern | bit
}
}
return bitPattern
}
错误
"_specialize属性"中的未知参数 UInt8
对此有任何线索/建议吗?
你只需要在专门的定义中包含一个 where 子句,如下所示
@_specialize(where T == UInt8)