<commit_before>//
//  TimeZonePickerViewController.swift
//  TimeZonePicker
//
//  Created by <NAME> on 19/07/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

public final class TimeZonePickerViewController: UIViewController {
    
    @IBOutlet weak var searchBar: UISearchBar!
    @IBOutlet weak var tableView: UITableView!
    
    public class func getVC(withDelegate delegate: TimeZonePickerDelegate) -> UINavigationController {
        let storyboard = UIStoryboard(name: "TimeZonePicker", bundle: Bundle(for: TimeZonePickerViewController.self))
        let nc = storyboard.instantiateInitialViewController() as! UINavigationController
        if let vc = nc.topViewController as? TimeZonePickerViewController {
            vc.delegate = delegate
        }
        return nc
    }
    
    fileprivate lazy var dataSource: TimeZonePickerDataSource = {
        let ds = TimeZonePickerDataSource(tableView: self.tableView, delegate: self)
        return ds
    }()
    
    weak var delegate: TimeZonePickerDelegate?

    override public func viewDidLoad() {
        super.viewDidLoad()
        configureTableView()
        configureSearchBar()
    }
    
    override public func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        update()
    }
    
    private func update() {
        dataSource.update { _ in
            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        }
    }
    
    private func configureTableView() {
        tableView.tableFooterView = UIView()
    }
    
    private func configureSearchBar() {
        searchBar.delegate = self
    }
    
}

extension TimeZonePickerViewController: UISearchBarDelegate {
    
    public func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        dataSource.filter(searchText)
        tableView.reloadData()
    }
    
}

extension TimeZonePickerViewController: TimeZonePickerDataSourceDelegate {
    
    func timeZonePickerDataSource(_ timeZonePickerDataSource: TimeZonePickerDataSource, didSelectTimeZone timeZone: NSTimeZone) {
        delegate?.timeZonePicker(self, didSelectTimeZone: timeZone)
    }
    
}
<commit_msg>make sure the search bar has focus when the timeZonePicker controller gets presented<commit_after>//
//  TimeZonePickerViewController.swift
//  TimeZonePicker
//
//  Created by <NAME> on 19/07/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

public final class TimeZonePickerViewController: UIViewController {
    
    @IBOutlet weak var searchBar: UISearchBar!
    @IBOutlet weak var tableView: UITableView!
    
    public class func getVC(withDelegate delegate: TimeZonePickerDelegate) -> UINavigationController {
        let storyboard = UIStoryboard(name: "TimeZonePicker", bundle: Bundle(for: TimeZonePickerViewController.self))
        let nc = storyboard.instantiateInitialViewController() as! UINavigationController
        if let vc = nc.topViewController as? TimeZonePickerViewController {
            vc.delegate = delegate
        }
        return nc
    }
    
    fileprivate lazy var dataSource: TimeZonePickerDataSource = {
        let ds = TimeZonePickerDataSource(tableView: self.tableView, delegate: self)
        return ds
    }()
    
    weak var delegate: TimeZonePickerDelegate?

    override public func viewDidLoad() {
        super.viewDidLoad()
        configureTableView()
        configureSearchBar()
    }
    
    override public func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        update()
        DispatchQueue.main.async {
            self.searchBar.becomeFirstResponder()
        }
    }
    
    private func update() {
        dataSource.update { _ in
            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        }
    }
    
    private func configureTableView() {
        tableView.tableFooterView = UIView()
    }
    
    private func configureSearchBar() {
        searchBar.delegate = self
    }
    
}

extension TimeZonePickerViewController: UISearchBarDelegate {
    
    public func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        dataSource.filter(searchText)
        tableView.reloadData()
    }
    
}

extension TimeZonePickerViewController: TimeZonePickerDataSourceDelegate {
    
    func timeZonePickerDataSource(_ timeZonePickerDataSource: TimeZonePickerDataSource, didSelectTimeZone timeZone: NSTimeZone) {
        delegate?.timeZonePicker(self, didSelectTimeZone: timeZone)
    }
    
}

{'fraction_non_alphanumeric': 0.07357422725293862, 'fraction_numerical': 0.0043535045711798, 'mean_word_length': 2.788128606760099, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6876495', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1211, 'n_words': 286}