73
70

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SwiftでのNSDataの変換

Last updated at Posted at 2015-01-22

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
73
70
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
73
70

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?