SwiftでのNSDataの変換
NSData <=> String
var str = "Hello";
// String to NSData
let data = str.dataUsingEncoding(NSUTF8StringEncoding)
// NSData to String
var out: String = NSString(data:data, encoding:NSUTF8StringEncoding)
println(out) // ==> Hello
NSData <=> NSInteger
var src: NSInteger = 2525
var out: NSInteger = 0
// NSInteger to NSData
let data = NSData(bytes: &src, length: sizeof(NSInteger))
// NSData to NSInteger
data.getBytes(&out, length: sizeof(NSInteger))
println(out) // ==> 2525