ZetrixWeb ZetrixWeb - 3 months ago 10
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

try this

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