[swift-users] Why does withUnsafePointer(to:) require a var argument?
Rick Mann
rmann at latencyzero.com
Thu Apr 27 21:31:11 CDT 2017
> On Apr 27, 2017, at 18:56 , Hooman Mehr <hooman at mac.com> wrote:
>
> You should be able to type your `dataBuffer ` as [Int8] (Byte array). Then you won’t need `withUnsafeMutableBytes`. You can simply call it like this:
>
> self.request = c_library_call(¶ms, dataBuffer) // Call as if it is a C array
Hmm. I'm not able to pass self.dataBuffer or self.dataBuffer! to the call. It's expecting `UnsafeMutableRawPointer!`.
>
> It works because of C interoperability compiler magic.
>
> As long as the instance holding `dataBuffer` is not deallocated and you have not resized the array, the pointer should remain valid.
--
Rick Mann
rmann at latencyzero.com
More information about the swift-users
mailing list