Created
August 23, 2014 23:53
-
-
Save nolili/2bf1a701df1015ed6488 to your computer and use it in GitHub Desktop.
SwiftのArray(バイト列)からNSDataへ変換
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 UIKit | |
var str = "Hello, playground" | |
// Swiftの配列からNSDataへ変換 | |
var rawArray:[UInt8] = [0x01, 0x02, 0x03]; | |
let data = NSData(bytes: &rawArray, length: rawArray.count) | |
print(data) | |
// バイト列からNSDataに変換 | |
// 0x00, 0x00, 0x00 のバッファを作成 | |
var buffer = [UInt8](count: 3, repeatedValue: 0x00) | |
data.getBytes(&buffer, length: 3) | |
print(buffer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot.