title: Elements for array getting from server, randomly different order (swift)
body: <p>In viewDidLoad I have such code:</p>
  
  <pre><code>Alamofire.request(.GET, "http://my1test.ru/applejesus.php?task=getCategoryCount").responseString(encoding: NSUTF8StringEncoding) { (request, response, string, error) -&gt; Void in
          let count = string!.toInt()!
          println(count)
  
          for var i=1; i&lt;=count; i++ {
            //  println(i)
              lib.httpGetAsNSData("http://my1test.ru/applejesus.php?task=getCategory&amp;categoryNumber=\(i)") {result in
                  let json = JSON(data: result)
                  let title = json["title"].stringValue
                  println("title: "+title)
                  if title.isEmpty == false {
                  NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "http://my1test.ru/aj/"+lib.urlencode(title)+".png")!) { (data, response, error) in
                      self.images.append(data)
                       self.catTitles.append(title)
                      //self.tableViewObject.reloadData()
                      }.resume()
                  }
              }
              }
          }
      }
  </code></pre>
  
  <p>First we request for categories count, second we loading their titles and adding them into array. Also there is an NSData-array with images for each category. Images loading from server too.</p>
  
  <p>Now please look at println("title: "+title)</p>
  
  <p>So my question is that order of parsed titles can be changed randomly. Why it happens, how should I fix it and if it not an random, what have I done wrong?</p>
  
  <p>In screenshots below you can see that 1 element always in different position</p>
  
  <p>If it needed, httpGetAsNSData listing:</p>
  
  <pre><code> class func httpGetAsNSData(url: String, completion: NSData -&gt; Void) {
      if url.isEmpty == false { var request = NSMutableURLRequest(URL: NSURL(string: url)!)
  
      request.HTTPMethod = "GET"
  
      request.addValue("text/html", forHTTPHeaderField: "Content-Type")
      request.addValue("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36", forHTTPHeaderField: "User-Agent")
      request.addValue("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", forHTTPHeaderField: "Accept")
      request.addValue("gzip, deflate, sdch", forHTTPHeaderField: "Accept-Encoding")
      request.addValue("max-age=0", forHTTPHeaderField: "Cache-Control")
  
      var session = NSURLSession.sharedSession()
  
      let task = session.dataTaskWithRequest(request, completionHandler: { data, response, error in
  
          if error != nil {
  
              println(error.localizedDescription)
  
          }
  
          completion(data)
  
      })
  
      task.resume()
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/AqyVE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AqyVE.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/dfon0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dfon0.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/JqFfo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JqFfo.png" alt="enter image description here"></a></p>