[swift-users] Swift 3 and bytes

Jens Persson jens at bitcycle.com
Sun Sep 25 14:05:56 CDT 2016


Use UnsafeMutableRawPointer.

On Sun, Sep 25, 2016 at 1:28 PM, Gerriet M. Denkmann via swift-users <
swift-users at swift.org> wrote:

> Got:
> var bitField : UnsafeMutablePointer<UInt32>
> bitField = UnsafeMutablePointer< UInt32 >.allocate(capacity: 912)
>
> But now I want to read a certain range as bytes (not as UInt32);
>
> let staP = bitField + 23
> let endP = bitField + 99
>
> let staB = UnsafeMutablePointer<UInt8>(staP)    ← this does not work in
> Swift 3
> let endB = UnsafeMutablePointer<UInt8>(endP)
>
> let result = someFunction( from: staB, until: endB ) // does something for
> bytes staB ..< endB
>
> Xcode hints about “withMemoryRebound”, but I cannot figure out the correct
> syntax.
>
> Gerriet
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160925/7f93905d/attachment.html>


More information about the swift-users mailing list