Created
June 20, 2017 16:00
-
-
Save ainame/8629facc6b734ad7f5fa5f9224c42ff7 to your computer and use it in GitHub Desktop.
Fast?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Darwin | |
let string = "hello world" | |
var array = [UInt8]() | |
string.withCString { ptr in | |
print("strlen: \(strlen(ptr))") | |
let length = strlen(ptr) | |
var currentPtr = ptr | |
var i = 0 | |
while i != length { | |
print("pointee: \(currentPtr.pointee), char: \(Unicode.Scalar(Int(currentPtr.pointee))!)") | |
array.append(UInt8(currentPtr.pointee)) | |
currentPtr = currentPtr.successor() | |
i += 1 | |
} | |
} | |
print(array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment