I am trying to manually convert Swift 3 code to Swift 5, but am getting error when trying to cast memory.
let buffer: UnsafePointer<Int16>
init<T>(buffer: UnsafePointer<T>) {
self.buffer = UnsafePointer<Int16>(buffer)
}
The error is forced typecast which new Swift version is not allowing.
Cannot convert value of type 'UnsafePointer<T>' to expected argument type 'UnsafePointer<Int16>'
I am not sure what is the right way to rebind memory to 'UnsafePointer<Int16>', forcibly.
The
UnsafePointerreference page explains the correct, but tedious, procedure:You're supposed to tell the compiler how much memory you're rebinding (using the
capacityparameter) because it may have already copied some of that memory to registers or the stack and it needs to know you're invalidating those copies.