I'm using a simple extension to pack and unpack data, the code below currently still works but it's throwing me a warning and I'd like to update it to prevent issues down the line.
There are two similar questions asked about this, but I haven't been able to successfully apply what has been discusses there. So I was hoping someone could give me some insight.
The extension that's throwing the warning:
extension Data {
var unsafeBytes : UnsafePointer<UInt8> {
return self.withUnsafeBytes { return $0 } //'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
}
}
One of the functions that uses it:
func upack(_ bin: Data) -> Data {
let unsafeBin = bin.unsafeBytes
let output = UnsafeMutablePointer<UInt8>.allocate(capacity: 540)
if (!nfc_upack(key, unsafeBin, output)) {
log.warning("Unpacking failed")
}
return Data(bytes: output, count: 540)
}
Edit: nfc_upack
leads to https://github.com/socram8888/amiitool/blob/master/amiibo.c#L73
Like I said, currently it's working fine, but I'd like to solve this before it becomes an issue.