将 NSData 转换为其他类型

字符串

迅速

let string = String(NSString(data: data, encoding: NSUTF8StringEncoding)) //assuming data is a valid NSData object

Objective-C

NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; //assuming data is a valid NSData object
[string release];

到数组

迅速

let array = data.bytes as! NSMutableArray //assuming data is a valid NSData object

Objective-C

NSMutableArray *array = (NSMutableArray *)[data bytes]; //assuming data is a valid NSData object

到字节数组

迅速

let bytesArray = data.bytes as! UInt8 //assuming data is a valid NSData object

Objective-C

UInt8 *bytesArray = (UInt8 *)data.bytes; //assuming data is a valid NSData object