本文介绍了迁移到Swift 5后,SQLite.swift出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用SQLite.swift,升级到Swift 5后,库中出现错误.请帮助我重写该方法.
I use SQLite.swift and after upgrading to Swift 5 an error appears in the library. Please help me rewrite the method.
错误:
'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)
}
}
推荐答案
直到SQLite.swift
不会发布任何更新,并带有您可以尝试手动修改SQLite/Foundation.swift
for fromDatatypeValue(_ dataValue: Blob)
函数和计算所得的属性通过这种方式:
Till SQLite.swift
doesn't release any update with the fix you could try modify manually the SQLite/Foundation.swift
for fromDatatypeValue(_ dataValue: Blob)
function and the computed property datatypeValue
in this way:
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)
}
}
这篇关于迁移到Swift 5后,SQLite.swift出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!