Problem with SQLite.swift after migration to Swift 5

☆樱花仙子☆ 提交于 2019-12-08 05:03:01

问题


I use SQLite.swift and after upgrading to Swift 5 an error appears in the library. Please help me rewrite the method.

Error:

'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead

Code:

public var datatypeValue: Blob {
    return withUnsafeBytes { (pointer: UnsafePointer<UInt8>) -> Blob in
        return Blob(bytes: pointer, length: count)
    }
}

回答1:


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


来源:https://stackoverflow.com/questions/55570433/problem-with-sqlite-swift-after-migration-to-swift-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!