<commit_before>//
//  ListOfCitiesTableViewController.swift
//  PrevisaoDoTempo
//
//  Created by <NAME> on 03/02/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit
import JGProgressHUD

class ListOfCitiesTableViewController: UITableViewController, UISearchBarDelegate, SearchCityDelegate {

    @IBOutlet weak var searchBar: UISearchBar!
    
    var hud: JGProgressHUD?
    
    var controller = APIController()
    var cities: [City]?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        controller.searchCitydelegate = self
        searchBar.delegate = self
        
        hud = JGProgressHUD(style: .Dark)
        hud!.textLabel!.text = "Buscando"
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        searchBar.resignFirstResponder()
        
        if segue.identifier == "Show Weather For City" {
            let vc = segue.destinationViewController as! CityWeatherViewController
            let index = tableView.indexPathForSelectedRow!.row
            let city = cities![index]
            vc.city = city
        }
    }
    
    func listCitiesWith(cities: [City]) {
        self.cities = cities
        self.tableView.reloadData()
    }
    
    func hideActivityIndicator() {
        hud!.dismiss()
    }
    
    func showActivityIndicator() {
        hud!.showInView(self.view)
        searchBar.resignFirstResponder()
    }
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if let list = cities {
            return list.count
        }
        return 0
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("City Cell", forIndexPath: indexPath)
        let city = cities![indexPath.row]<commit_msg>Using didSet to reload tableView when data source is updated<commit_after>//
//  ListOfCitiesTableViewController.swift
//  PrevisaoDoTempo
//
//  Created by <NAME> on 03/02/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit
import JGProgressHUD

class ListOfCitiesTableViewController: UITableViewController, UISearchBarDelegate, SearchCityDelegate {

    @IBOutlet weak var searchBar: UISearchBar!
    
    var hud: JGProgressHUD?
    
    var controller = APIController()
    
    var cities: [City]? {
        
        didSet {
            tableView.reloadData()
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        controller.searchCitydelegate = self
        searchBar.delegate = self
        
        hud = JGProgressHUD(style: .Dark)
        hud!.textLabel!.text = "Buscando"
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        searchBar.resignFirstResponder()
        
        if segue.identifier == "Show Weather For City" {
            let vc = segue.destinationViewController as! CityWeatherViewController
            let index = tableView.indexPathForSelectedRow!.row
            let city = cities![index]
            vc.city = city
        }
    }
    
    func listCitiesWith(cities: [City]) {
        self.cities = cities
    }
    
    func hideActivityIndicator() {
        hud!.dismiss()
    }
    
    func showActivityIndicator() {
        hud!.showInView(self.view)
        searchBar.resignFirstResponder()
    }
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if let list = cities {
            return list.count
        }
        return 0
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("City Cell", forIndexPath: indexPath)
        let city = cities![indexPath.row]
{'fraction_non_alphanumeric': 0.0836144578313253, 'fraction_numerical': 0.005783132530120482, 'mean_word_length': 2.3502824858757063, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6036373', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1182, 'n_words': 269}