[swift-users] Swift 3 version of creating a string from a pointer, length and encoding?

Quinn "The Eskimo!" eskimo1 at apple.com
Fri Sep 30 03:25:32 CDT 2016


On 29 Sep 2016, at 10:47, John Brownie via swift-users <swift-users at swift.org> wrote:

> Or is there a better way that I've missed (highly possible)?

I don’t think there’s anything significantly better.  The other two options I can think of:

* use the `UTF8` codec

* use NSString

NSString(bytes: bytes, length: length, encoding: String.Encoding.utf8.rawValue) as? String

Honestly, I think bouncing through `Data` is better.

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware




More information about the swift-users mailing list