Last active
October 18, 2017 05:30
-
-
Save yossan/efa230df61c10012e530e937dc4bd894 to your computer and use it in GitHub Desktop.
converts string to little endian in 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
import Foundation | |
let str = "βππβ" | |
// returns little endian | |
let data = str.withCString(encodedAs: UTF16.self) { (lead) -> Data in | |
let ret = UnsafeBufferPointer(start: lead, count: str.utf16.count) | |
let data = Data(buffer: ret) | |
return data | |
} | |
let decode = String(data: data, encoding: .utf16LittleEndian)! | |
print(decode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment