-1
let parameterDictionary = ["action": "create",   "email": emailTextField?.text, "password":  passwordTextField.text] as [String : Any]
var request = URLRequest(url: serviceUrl)
request.httpMethod = "POST"
request.setValue(" application/json", forHTTPHeaderField: "Content-Type")

how can i get a dynamic value to a textfield and convert it into base64 value for password

Talha Junaid
  • 2,351
  • 20
  • 29
raj kumar
  • 1
  • 1

2 Answers2

0

So it appears you have a String value, there are no methods directly on this type to produce base64 encoding. However there are such methods on Data, and you can convert a String value to an equivalent Data value.

Look at String's function data(using:) – it will allow you to obtain a Data value consisting of the UTF-8 bytes corresponding to a String value (this function is documented under StringProtocol, which String implements). Now look at Data's documentation, search for base64.

CRD
  • 52,522
  • 5
  • 70
  • 86
0

Try this it's Work for me.

func toBase64EncodedString(_ jsonString : String) -> String
{
    let utf8str = jsonString.data(using: .utf8)

    let base64Encoded = utf8str?.base64EncodedString(options: [])

    return base64Encoded!
}
Nikunj Kumbhani
  • 3,758
  • 2
  • 26
  • 51