Created
September 18, 2015 15:30
-
-
Save masters3d/b436c105742f74ce9c18 to your computer and use it in GitHub Desktop.
Print chars from c api with swift
This file contains hidden or 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
// 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