Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController, UITableViewDelegate {
- var arrayLength:Int = 0
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- let urlPath = "http://example.com/en/json"
- let url = NSURL(string: urlPath)!
- let session = NSURLSession.sharedSession()
- let task = session.dataTaskWithURL(url, completionHandler: {
- data, response, error in
- if (error? != nil) {
- println(error)
- } else {
- var jsonResponse: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil)
- let json = JSON(jsonResponse!)
- self.arrayLength = json["dump"].array?.count as Int!
- //println("Second: \(self.arrayLength)")
- for postIndex in 0...self.arrayLength-1 {
- //println(json["dump"][postIndex]["title"])
- }
- }
- func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- println(self.arrayLength)
- return self.arrayLength
- }
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
- cell.textLabel?.text = "Test"
- return cell
- }
- })
- task.resume()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement