Swift HTTP POST login validation
<p>Currently working on an iOS app where HTTP POST method is needed to communicate with the server. Getting the username and password if is correct or not is a success, but the server returns as string 
for example:</p>

<p>If correct username and password:</p>

<blockquote>
  <p>&lt;string> Correct &lt;/string></p>
</blockquote>

<p>if incorrect username or password:</p>

<blockquote>
  <p>&lt;string> Incorrect &lt;/string></p>
</blockquote>

<p>How can I add validation as in:
If the current username and password are correct go to the next ViewController, but if the current username or password is incorrect display an error message without going to next ViewController.</p>

<p>This is the code I am using:</p>

<pre><code>import UIKit


class ViewController: UIViewController {
    @IBOutlet var passwordField: UITextField!
    @IBOutlet var usernameField: UITextField!


override func viewDidLoad() {
        super.viewDidLoad()

           }

    @IBAction func LoginGetData(_ sender: Any) {


        var request = URLRequest(url: URL(string: "http://mylinkinhere")!)
        request.httpMethod = "POST"
        let postString = "username=\(usernameField.text!)&amp;password=\(passwordField.text!)"
        request.httpBody = postString.data(using: .utf8)
        let task = URLSession.shared.dataTask(with: request) { data, response, error in
            guard let data = data, error == nil else {
                print("error=\(error)")
                return
            }

             let httpStatus = response as? HTTPURLResponse
                print("statusCode should be 200, but is \(httpStatus!.statusCode)")
                print("response = \(response)")
                print(postString)

            let responseString = String(data: data, encoding: .utf8)
            print("responseString = \(responseString)")

        }
        task.resume()
    }
}
</code></pre>

<p>thank you.</p>