[swift-users] Data withUnsafeBytes

Ole Begemann ole at oleb.net
Sun Sep 4 14:59:55 CDT 2016


The compiler has no way of inferring the type of the generic ContentType 
parameter because you're not using that parameter anywhere in the body 
of the closure that could give the compiler a hint. So you have to 
provide the type manually by explicitly annotating the type of the 
closure's parameter.

For example, if you want to treat `items` as a series of `UInt8` values:

     let tryThis = items.withUnsafeBytes {
         (bytes: UnsafePointer<UInt8>) -> Int in
         return 1
     }

I agree the compiler diagnostic should probably be better, though.

Ole



More information about the swift-users mailing list