1

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 Answer 1

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)
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. Works great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.