I\'m trying to ultimately have an NSMutableURLRequest
with a valid HTTPBody
, but I can\'t seem to get my string data (coming from a UITextFie
To create not optional data I recommend using it:
let key = "1234567"
let keyData = Data(key.utf8)
Swift 4.2
let data = yourString.data(using: .utf8, allowLossyConversion: true)
Here very simple method
let data = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)