[swift-users] withUnsafeMutableBytes is killing me
Rick Mann
rmann at latencyzero.com
Tue Apr 25 03:45:00 CDT 2017
The following playground reproduces an issue I'm having, in that the code won't compile depending on the content of the closure. In fact, an empty closure is fine, but when I try to call certain things, it's not.
I figure it has something to do with the type inference for inPointer, but I can't figure out what it needs to work.
---------------------------
import Foundation
// OKAY:
var msg = Data(capacity: 123456)
msg.withUnsafeMutableBytes
{ (inPointer) -> Void in
foo(inPointer)
}
//error: cannot convert value of type '(_) -> Void' to expected argument type '(UnsafeMutablePointer<_>) -> _'
//{ (inPointer) -> Void in
//^~~~~~~~~~~~~~~~~~~~~~~~
msg.withUnsafeMutableBytes
{ (inPointer) -> Void in
}
//error: cannot convert value of type '(_) -> Void' to expected argument type '(UnsafeMutablePointer<_>) -> _'
//{ (inPointer) -> Void in
//^~~~~~~~~~~~~~~~~~~~~~~~
msg.withUnsafeMutableBytes
{ (inPointer) -> Void in
var s: Int
lgs_error(inPointer, 123456, &s)
}
func
foo(_ data: UnsafeMutableRawPointer!)
{
}
func
lgs_error(_ message: UnsafeMutablePointer<Int8>!,
_ message_capacity: Int,
_ message_size: UnsafeMutablePointer<Int>!) -> Int
{
}
---------------------------
--
Rick Mann
rmann at latencyzero.com
More information about the swift-users
mailing list