ZetrixWeb ZetrixWeb - 1 year ago 110
Swift Question

Converting issue Obective-c to swift

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

i want to convert above string to swift.

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

i have tried something above but not working in xcode 7.3.1

i have also tried to convert using https://objectivec2swift.com/#/home/main but fails to achieve.

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