迁移到Swift 5后,SQLite.swift出现问题

时间:2019-04-08 09:39:19

标签: sqlite.swift swift5

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

1 个答案:

答案 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)
    }
}