我使用SQLite.swift,升级到Swift 5后,库中出现错误。请帮助我重写该方法。
错误:
'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
代码:
public var datatypeValue: Blob {
return withUnsafeBytes { (pointer: UnsafePointer<UInt8>) -> Blob in
return Blob(bytes: pointer, length: count)
}
}
答案 0 :(得分:1)
在SQLite.swift
之前不会发布任何更新,您可以尝试通过以下方式手动修改SQLite/Foundation.swift
函数的fromDatatypeValue(_ dataValue: Blob)
和计算属性datatypeValue
:< / p>
public static func fromDatatypeValue(_ dataValue: Blob) -> Data {
return Data(dataValue.bytes)
}
public var datatypeValue: Blob {
return withUnsafeBytes { (pointer: UnsafeRawBufferPointer) -> Blob in
return Blob(bytes: pointer.baseAddress!, length: count)
}
}