ZetrixWeb ZetrixWeb -4 years ago 135
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 Source

try this

var myRequestData = NSData(bytes: (encryptedStr as NSString).UTF8String, length: encryptedStr.characters.count)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download