ZetrixWeb ZetrixWeb - 3 months ago 19
Objective-C Question

Converting issue Objective-C to Swift

NSData *myRequestData = [NSData dataWithBytes: [encryptedStr UTF8String] length: [encryptedStr length]];


I want to convert the above string to Swift.

var myRequestData = NSData(bytes: encryptedStr.UTF8String(), length: encryptedStr.length())!


I have tried something above but it is not working in Xcode 7.3.1.

I have also tried to convert using https://objectivec2swift.com/#/home/main but failed.

Answer

try this

var myRequestData = NSData(bytes: (encryptedStr as NSString).UTF8String, length: encryptedStr.characters.count)