Skip to content

Instantly share code, notes, and snippets.

@masters3d
Created September 18, 2015 15:30
Show Gist options
  • Save masters3d/b436c105742f74ce9c18 to your computer and use it in GitHub Desktop.
Save masters3d/b436c105742f74ce9c18 to your computer and use it in GitHub Desktop.
Print chars from c api with swift
// use this extension
//https://gist.github.com/masters3d/b90a99aac6b923add0ee
import Darwin
var date0 = tm()
var chars = asctime(&date0)
var toReturnString = ""
while chars.successor().memory != 0 {
let scalar = chars.memory
let unsigned8 = UInt8(scalar)
toReturnString.append(
// Convert UTF8 codes to Swift Characters
Character(UnicodeScalar(UInt32(unsigned8)))
)
chars = chars.successor()
}
print(toReturnString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment