Re: [swift-users] Can't initialise using a UTF8 string from within 'withUnsafeBufferPointer' expression

2016-07-18 Thread Brent Royal-Gordon via swift-users
> On Jul 18, 2016, at 11:44 AM, Karl via swift-users > wrote: > > Also, as interesting as that may be, I’m also curious what to do in the > general case for types without magic compiler optimisations. Wait for Swift 4, apparently: https://github.com/apple/swift-evolution/blob/master/proposals

Re: [swift-users] Can't initialise using a UTF8 string from within 'withUnsafeBufferPointer' expression

2016-07-18 Thread Karl via swift-users
> On 18 Jul 2016, at 14:51, Martin R wrote: > > This is not an answer to your question, but note that you can pass a Swift > String to functions expecting an UnsafePointer (C String) parameter, > and the compiler will generate a temporary NUL-terminated UTF-8 > representation for you: > > l

Re: [swift-users] Can't initialise using a UTF8 string from within 'withUnsafeBufferPointer' expression

2016-07-18 Thread Martin R via swift-users
This is not an answer to your question, but note that you can pass a Swift String to functions expecting an UnsafePointer (C String) parameter, and the compiler will generate a temporary NUL-terminated UTF-8 representation for you: let io = DispatchIO(type: .stream, path: "/path/to/file", ...

[swift-users] Can't initialise using a UTF8 string from within 'withUnsafeBufferPointer' expression

2016-07-17 Thread Karl via swift-users
As I understand it, we are supposed to use withUnsafe{Mutable/Buffer}Pointer or withExtendedLifetime to guarantee that objects we take pointers of will exist and won’t be optimised out by the compiler. However, this leads to a problem when trying to initialise something which expects a UTF8 str