I am migrating a project to Swift 4 and I cannot figure out how I am supposed to use the new API:s to do this in Swift 4. The following code is the old Swift 3 way (from the middle of a function hence the guard):
let formattedString = "A string"
guard let stringData: Data = formattedString.data(using: .utf8) else { return }
let data: DispatchData = [UInt8](stringData).withUnsafeBufferPointer { (bufferPointer) in
return DispatchData(bytes: bufferPointer)
}
Now it gives the following warning: init(bytes:)' is deprecated: Use init(bytes: UnsafeRawBufferPointer) instead
In order to do that you need to get access to a variable with the type UnsafeRawBufferPointer
instead of UnsafeBufferPointer<UInt8>