Advertisement
Guest User

Untitled

a guest
Apr 7th, 2015
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import UIKit
  3.  
  4. class ViewController: UIViewController, UITableViewDelegate {
  5.     var arrayLength:Int = 0
  6.    
  7.     override func viewDidLoad() {
  8.         super.viewDidLoad()
  9.         // Do any additional setup after loading the view, typically from a nib.
  10.        
  11.         let urlPath = "http://example.com/en/json"
  12.        
  13.         let url = NSURL(string: urlPath)!
  14.         let session = NSURLSession.sharedSession()
  15.        
  16.         let task = session.dataTaskWithURL(url, completionHandler: {
  17.             data, response, error in
  18.            
  19.             if (error? != nil) {
  20.                 println(error)
  21.             } else {
  22.                 var jsonResponse: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil)
  23.                
  24.                 let json = JSON(jsonResponse!)
  25.                 self.arrayLength = json["dump"].array?.count as Int!
  26.                 //println("Second: \(self.arrayLength)")
  27.                
  28.                 for postIndex in 0...self.arrayLength-1 {
  29.                     //println(json["dump"][postIndex]["title"])
  30.                 }
  31.             }
  32.            
  33.             func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  34.                 println(self.arrayLength)
  35.                 return self.arrayLength
  36.             }
  37.            
  38.              func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  39.                 let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
  40.                 cell.textLabel?.text = "Test"
  41.                 return cell
  42.             }
  43.         })
  44.        
  45.         task.resume()
  46.     }
  47.    
  48.     override func didReceiveMemoryWarning() {
  49.         super.didReceiveMemoryWarning()
  50.         // Dispose of any resources that can be recreated.
  51.     }
  52.    
  53.    
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement