title: Swift 2 Function Call and JSON usage
body: <p>I have a Problem with Swift and Xcode 7.</p>
  
  <pre><code>class ConnectVC: UITableViewController {
  
  var username:Array&lt; String &gt; = Array &lt; String &gt;()
  
  var TableData:Array&lt; String &gt; = Array &lt; String &gt;()
  
  var pictures:Array&lt; String &gt; = Array &lt; String &gt;()
  
  var profile_pictures:Array&lt; String &gt; = Array &lt; String &gt;()
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      get_data_from_url("-url-")
  
  }
  
  override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      return 1
  }
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return TableData.count
  }
  
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ConnectVCCell
  
      let picture = pictures[indexPath.row]
      print(pictures.count)
      print(picture)
      print(profile_pictures.count)
      let pic = profile_pictures[indexPath.row]
  
      if picture != "" {
          let aString = "-url-"
          let url = NSURL(string: aString)
          let data = NSData(contentsOfURL: url!)
          print(url)
          let image = UIImage(data: data!)
  
          cell.imageURL.image = image
      }else{
          print("No picture")
          cell.imageURL.image = nil
      }
  
      cell.mainLabel.text = TableData[indexPath.row]
      return cell
  }
  
  
  func get_data_from_url(url:String)
  {
      let url = NSURL(string: url)
      let urlRequest = NSMutableURLRequest(URL: url!,
          cachePolicy: .ReloadIgnoringLocalAndRemoteCacheData,
          timeoutInterval: 15.0)
      let queue = NSOperationQueue()
      NSURLConnection.sendAsynchronousRequest(
          urlRequest,
          queue: queue,
          completionHandler: {response, data, error in
              if data!.length &gt; 0 &amp;&amp; error == nil{
                  let json = NSString(data: data!, encoding: NSASCIIStringEncoding)
                  self.extract_json(json!)
              }else if data!.length == 0 &amp;&amp; error == nil{
                  print("Nothing was downloaded")
              } else if error != nil{
                  print("Error happened = \(error)")
              }
          }
      )
  }
  
  func extract_json(data:NSString)
  {
  
      let jsonData:NSData = data.dataUsingEncoding(NSASCIIStringEncoding)!
  
      do {
          // Try parsing some valid JSON
          let json: AnyObject? = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .AllowFragments)
  
          let data_list = json as? NSArray
  
          for (var i = 0; i &lt; data_list!.count ; i++ )
          {
              if let data_obj = data_list![i] as? NSDictionary
              {
                  if let text = data_obj["text"] as? String
                  {
                      if let picture = data_obj["picture"] as? String
                      {
                          if let user = data_obj["user"] as? String
                          {
  
                              self.save_image("-url-")
  
                              TableData.append(text + " [" + user + "]")
                              pictures.append(picture)
                          }
                      }
                  }
              }
          }
      }
      catch let error as NSError {
          // Catch fires here, with an NSErrro being thrown from the JSONObjectWithData method
          print("A JSON parsing error occurred, here are the details:\n \(error)")
      }
      do_table_refresh();
  }
  
  func save_image(url:String){
  
      let url = NSURL(string: url)
      let urlRequest = NSMutableURLRequest(URL: url!,
          cachePolicy: .ReloadIgnoringLocalAndRemoteCacheData,
          timeoutInterval: 15.0)
      let queue = NSOperationQueue()
      NSURLConnection.sendAsynchronousRequest(
          urlRequest,
          queue: queue,
          completionHandler: {response, data, error in
              if data!.length &gt; 0 &amp;&amp; error == nil{
                  let json = NSString(data: data!, encoding: NSASCIIStringEncoding)
                  self.extract_json_picture(json!)
              }else if data!.length == 0 &amp;&amp; error == nil{
                  print("Nothing was downloaded")
              } else if error != nil{
                  print("Error happened = \(error)")
              }
          }
      )
  }
  func extract_json_picture(data:NSString)
  {
      let jsonData:NSData = data.dataUsingEncoding(NSASCIIStringEncoding)!
  
      do {
          // Try parsing some valid JSON
          let json: AnyObject? = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .AllowFragments)
  
          print(json)
  
          let user_info = json as? NSArray
  
          if let user_list = user_info![0] as? NSDictionary
          {
              if let profile_picture = user_list["picture"] as? String
              {
                  profile_pictures.append(profile_picture)
              }
          }
  
      }
      catch{
  
          print("A JSON parsing error occurred, here are the details:\n \(error)")
  
      }
  </code></pre>
  
  <p>With this Code I get the following Error: </p>
  
  <blockquote>
    <p>fatal error: Array index out of range</p>
  </blockquote>
  
  <p>in the following line: </p>
  
  <pre><code>let pic = profile_pictures[indexPath.row]
  </code></pre>
  
  <p>The Problem is, that the array is empty. But I don't see the Problem. I think the function where I fill the array is correctly called.</p>
  
  <p>Can someone help?</p>