Reputation: 1354
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)
}
}
Upvotes: 1
Views: 639
Reputation: 6547
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)
}
}
Upvotes: 1