title: Populate tableview in swift
body: <p>I have this result after parsing XML result.</p>
  
  <p>When I do a <code>println()</code> I get the result perfectly like this</p>
  
  <pre><code>{
     description = "Suzuki SX4 - BB71521";
     deviceID = 359710042040320;
  }
  {
     description = "Chevrolet Tahoe Noir - Demonstration";
     deviceID = 359710042067463;
  }
  {
     description = "Isuzu D'Max AA-08612";
     deviceID = 359710042091273;
  }
  {
     description = "Toyota 4 Runner";
     deviceID = 359710042110768;
  }
  </code></pre>
  
  <p>But when I try to parse the same result in an <code>UITableView</code> with two Cells, the <code>UITableView</code> appears empty.</p>
  
  <p>Please help me to populate only the table ???</p>
  
  <p>Here is my code</p>
  
  <pre><code>import UIKit
  
  class mtTableViewController: UITableViewController, NSXMLParserDelegate {
  
  var info = NSDictionary();
  var parser = NSXMLParser()
  var posts = NSMutableArray()
  var elements = NSMutableDictionary()
  var element = NSString()
  
  override func viewDidLoad()
  {
      super.viewDidLoad() 
      self.beginParsing()                                                                                                                                                                                                                       
  }
  
  override func didReceiveMemoryWarning()
  {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  func beginParsing()
  {
  
      let url = NSURL(string: "http://localhost:8080")
      var auth =
  
      "&lt;GTSRequest command=\"dbget\"&gt;" +
          "&lt;Authorization account=\"" + "easytrucking" + "\" user=\"" + "admin" + "\" password=\"" + "T8095634934ht" + "\"/&gt;" +
          "&lt;Record table=\"Device\" partial=\"true\"&gt;" +
          "&lt;Field name=\"accountID\"&gt;" + "easytrucking" + "&lt;/Field&gt;" +
          "&lt;Field name=\"description\"/&gt;" +           
          "&lt;/Record&gt;" +
      "&lt;/GTSRequest&gt;";
  
      //   "&lt;Authorization account=\"" + txtAccount.text + "\" user=\"" + txtUserName.text + "\" password=\"" + txtPassword.text + "\"/&gt;" +
  
      let request = NSMutableURLRequest(URL: url!)
      request.HTTPMethod = "POST"
      request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
      let data : NSData = (auth).dataUsingEncoding(NSUTF8StringEncoding)!;
      request.HTTPBody = data;
      NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {(response, data, error) in
    /// println(NSString(data: data, encoding: NSUTF8StringEncoding))
  
        let xml = SWXMLHash.parse(data)
  
          let count = xml["GTSResponse"]["Record"].all.count
  
          for var i = 0; i &lt; count; i++
          {
  
              if (xml["GTSResponse"]["Record"][i]["Field"][1].element?.attributes["name"] == "deviceID")
              {
  
                  self.elements.setObject((xml["GTSResponse"]["Record"][i]["Field"][1].element?.text)!, forKey: "deviceID")
  
              }
              if (xml["GTSResponse"]["Record"][i]["Field"][3].element?.attributes["name"] == "description")
              {
                  self.elements.setObject((xml["GTSResponse"]["Record"][i]["Field"][3].element?.text)!, forKey: "description")
  
              }
              self.posts.addObject(self.elements)
  
  // here i print the result
              println(self.elements)
  
          } 
      }
  }
   //Tableview Methods
  
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int
  {
      return posts.count
  }
  
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell
  {
      var cell : UITableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
      if(cell == nil) {
          cell = NSBundle.mainBundle().loadNibNamed("Cell", owner: self, options: nil)[0] as UITableViewCell;
      }
  
      cell.textLabel?.text = posts.objectAtIndex(indexPath.row).valueForKey("deviceID") as NSString
      cell.detailTextLabel?.text = posts.objectAtIndex(indexPath.row).valueForKey("description") as NSString
  
      return cell as UITableViewCell
  }
  }
  </code></pre>
  
  <p>Please help !!!</p>