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)
    }
}
Vergiliy
  • 1,248
  • 1
  • 13
  • 22

1 Answers1

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)
    }
}
denis_lor
  • 6,212
  • 4
  • 31
  • 55