1

我使用 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)
    }
}
4

1 回答 1

1

直到SQLite.swift没有发布任何带有修复的更新,您可以尝试以这种方式手动修改SQLite/Foundation.swiftforfromDatatypeValue(_ dataValue: Blob)函数和计算属性datatypeValue

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)
    }
}
于 2019-04-09T12:27:46.167 回答