Q:

Use PHP Response to store/use data

I declared a function to send information from some textfields (POST), then I get a response with the information given. I also used components(separatedBy: String) to get an array with the information from every field. What am trying to do now is to use this information (one from the array) to store/use it so I can show the user, in a new view, the information saved.
My Swift looks like the following
      @IBAction func enviarInfo(_ sender: Any) {
      let request = NSMutableURLRequest(url: NSURL(string: "http://www.mydomain/index.php")! as URL)
      request.httpMethod = "POST"

      //The String with the vars that will be sent to the $_POST["var"]
      let postString = "nombre=\(nombreText.text!)&aPaterno=\(apaternoText.text!)&aMaterno=\(amaternoText.text!)&genero=\(genero.text! &email=\(emailText.text!)&telefono=\(telefonoText.text!)"

      request.httpBody = postString.data(using: String.Encoding.utf8)

      let task = URLSession.shared.dataTask(with: request as URLRequest) {
      data, response, error in

            if error != nil {
            print("error=\(String(describing: error))")
            return
            }

      print("response = \(String(describing: response))")

         let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)

         print("responseString = \(String(describing: responseString))")

      //Use a split method to get relevant information only
         let string: String = responseString! as String
         var str = string.components(separatedBy: "@@")

         let resultadoUno = str[1]
         var str2 = resultadoUno.components(separatedBy: ">>")

         let resultadoDos = str2[0]
         var str3 = resultadoDos.components(separatedBy: ";")
       }
  task.resume()     
}

If I print, for example, str3[5] I get the phone number, or a name with str3[0], but what I don't know is, how to save the data and show it to the user via labels (label.text = the value from the array).

A:

You can easily save Response string to UserDefaults, and restore and use them later.
First, define a class level constant as UserDefaults key:
let key = "responseString"

Second, save the string:
UserDefaults.standard.set(responseString, forKey: key)
UserDefaults.standard.synchronize()

Restore and use it when you need it:
    guard let repsonseString = UserDefaults.standard.object(forKey: key) as? String else {
        return
    }

    var strArray = repsonseString.components(separatedBy: "@@")
    if strArray.count > 0 {
        let str2 = strArray[0].components(separatedBy: ">>")
        // do something with str2
    }

    if strArray.count > 1 {
        let str3 = strArray[1].components(separatedBy: ";")
        if str3.count > 5 {
            self.phoneLabel.text = str3[5]
        }
    }

The better practice is the PHP returns the dictionary instead of array, like:
{
   phoneNumber:123456789,
   userName:"Joy"
}

You get the response on iOS and convert JSON dictionary to Swift dictionary, and parse it into a Model(Like a User class). Then it will be very convenient to access data like: self.phoneNumberLabel.text = user.phoneNumber

