[swift-users] Can't initialise using a UTF8 string from within 'withUnsafeBufferPointer' expression
razielim at gmail.com
Mon Jul 18 13:44:36 CDT 2016
> On 18 Jul 2016, at 14:51, Martin R <martinr448 at gmail.com> wrote:
> This is not an answer to your question, but note that you can pass a Swift String to functions expecting an UnsafePointer<Int8> (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", ...)
> So you don't need a convenience initializer for _this_ purpose.
Isn’t it kind of strange that we have such a hidden implicit conversion, yet we don’t have implicit widening conversions?
Also, as interesting as that may be, I’m also curious what to do in the general case for types without magic compiler optimisations.
More information about the swift-users