1
我正在將swift 2.3項目更新爲3.1,並且遇到轉換此功能的問題,特別是在一行中。無法將數據擴展轉換爲Swift 3.1和UnsafeRawPointer
這是對Data的擴展。
public func read<T: BinaryReadable>(offset f_offset: inout Int,
byteOrder: ByteOrder = .HostByteOrder) -> T? {
// Validate the specified offset boundary.
guard self.count >= (f_offset + MemoryLayout<T>.size) else {
return nil
}
//let dataPtr = Unsas
// Get data pointer at offset location.
// TROUBLE CONVERTING THIS LINE
let dataPtr = UnsafePointer<UInt8>(bytes).advancedBy(f_offset)
// Increment the offset position.
f_offset += MemoryLayout<T>.size
// Read data from offset location and return in specified endianess.
let retVal = UnsafeRawPointer(dataPtr).load(as: T.self)
return (byteOrder == .littleEndian) ? retVal.littleEndian : retVal.bigEndian
}
我似乎無法獲得行
let dataPtr = UnsafePointer<UInt8>(bytes).advancedBy(f_offset)
轉換爲使用UnsafeRawPointer。我已經嘗試過太多,沒有成功(編譯錯誤)。
什麼是正確的語法?