title: Converting Android Volley Request to iOS NSURL asynchronous request
body: <p>I have the following method in my Android app which I use for user login/registration. </p>
  
  <pre><code>public void registerUser(final String username, final String email, final String password) {
      pDialog.setMessage("Signing Up...");
      pDialog.show();
  
      request = new StringRequest(Method.POST, SL_URL, new Response.Listener&lt;String&gt;() {
          @Override
          public void onResponse(String s) {
              pDialog.dismiss();
              String[] split = s.split("Config.php");
              String after = split[1];
              try {
                  JSONObject jsonObject = new JSONObject(after);
                  boolean error = jsonObject.getBoolean("error");
                  if (error) {
                      String errorMsg = jsonObject.getString("error_msg");
                      Toast.makeText(getApplicationContext(),
                              errorMsg, Toast.LENGTH_LONG).show();
  
                  } else {
                      session.setLogin(true, username, email);
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          }
      }) {
          @Override
          protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
              HashMap&lt;String, String&gt; hashMap = new HashMap&lt;&gt;();
              hashMap.put("tag", "login");
              hashMap.put("username", name);
              hashMap.put("password", password);
              return hashMap;
          }
      };
      queue.add(request);
  }
  </code></pre>
  
  <p>Now I am writing my app for iOS and trying to replicate this in Swift. So far I have the following code: </p>
  
  <pre><code>let username = usernameTxt.text
          let password = passwordTxt.text
          let urlPath: String = "***"
          let url: NSURL = NSURL(string: urlPath)!
          let request1: NSMutableURLRequest = NSMutableURLRequest(URL: url)
  
          request1.HTTPMethod = "POST"
          let stringPost="tag=login&amp;username=" + username! + "&amp;password=" + password! // Key and Value
          NSLog(stringPost)
          let data = stringPost.dataUsingEncoding(NSUTF8StringEncoding)
  
          request1.timeoutInterval = 60
          request1.HTTPBody=data
          request1.HTTPShouldHandleCookies=false
  
          let queue:NSOperationQueue = NSOperationQueue()
  
          NSURLConnection.sendAsynchronousRequest(request1, queue: queue, completionHandler:{ (response: NSURLResponse?, data: NSData?, error: NSError?) -&gt; Void in
              do {
                 var jsonResult: NSDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
              } catch _ {}
  
          })
  </code></pre>
  
  <p>Now as someone new to iOS development and Swift in general, I have the following questions: </p>
  
  <ol>
  <li><p>What is the best way to replicate the progressDialog I use in Java in Swift, it must be visible until the request is complete and then it should be dismissed. I'm guessing this should be placed in the completionHandler, however I'm not sure which UI element to use for the progress Dialog.</p></li>
  <li><p>How do I obtain my response as a String and replicate the behaviour of the split function, and then convert the result of this into a jsonObject like I do in my Java code.</p></li>
  <li><p>What is the best way to replicate the Toast used to show the error message. I don't think using a dialog which must be closed with a button would be optimal here.</p></li>
  </ol>
  
  <p>Thank you.</p>