If you write Swift code a little easier than
var theData : UInt8 = 3 let data = NSData(bytes: &theData, length: 1)
it is relatively straightforward to translate this value to Objective-C:
uint8_t theData = 3; NSData *data = [NSData dataWithBytes:&theData length:1];
For multiple bytes you should use an array
var theData : [UInt8] = [ 3, 4, 5 ] let data = NSData(bytes: &theData, length: theData.count)
which translates to Objective-C as
uint8_t theData[] = { 3, 4, 5 }; NSData *data = [NSData dataWithBytes:&theData length:sizeof(theData)];
(and you can omit the operator address in the last statement, see for example, Why is the address of the array equal to its value in C? ).
source share