<commit_before>//
//  ViewController.swift
//  Counter
//
//  Created by <NAME> on 9/18/16.
//
//

import UIKit
import WatchConnectivity

class ViewController: UIViewController {
  
    @IBOutlet var tableView: UITableView!
    var counterData = [Int]()
    private let session: WCSession? = WCSession.isSupported() ? WCSession.default() : nil
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        configureWCSession()
    }
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        
        configureWCSession()
    }
    
    private func configureWCSession() {
        session?.delegate = self;
        session?.activate()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        self.title = "Count List"

        self.tableView.dataSource = self
    }
}

extension ViewController: WCSessionDelegate {
        
    func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
        //Use this to update the UI instantaneously (otherwise, takes a little while)
        DispatchQueue.main.async {
            if let counterValue = message["counterValue"] as? Int {
                self.counterData.append(counterValue)
                self.tableView.reloadData()
            }
        }
    }
    
    //Handlers in case the watch and phone watch connectivity session becomes disconnected
    func sessionDidDeactivate(_ session: WCSession) {
        
    }
    
    func sessionDidBecomeInactive(_ session: WCSession) {
        
    }
    
    func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
        
    }
}

extension ViewController: UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return counterData.count;
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellIdentifier = "CounterCell"
        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
        
        let counterValueString = String(counterData[indexPath.row])
        cell?.textLabel?.text = counterValueString
        
        return cell!

    }
}<commit_msg>Collapse functions we won't cover in the workshop<commit_after>//
//  ViewController.swift
//  Counter
//
//  Created by <NAME> on 9/18/16.
//
//

import UIKit
import WatchConnectivity

class ViewController: UIViewController {
  
    @IBOutlet var tableView: UITableView!
    var counterData = [Int]()
    private let session: WCSession? = WCSession.isSupported() ? WCSession.default() : nil
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        configureWCSession()
    }
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        
        configureWCSession()
    }
    
    private func configureWCSession() {
        session?.delegate = self;
        session?.activate()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        self.title = "Count List"

        self.tableView.dataSource = self
    }
}

extension ViewController: WCSessionDelegate {
        
    func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
        //Use this to update the UI instantaneously (otherwise, takes a little while)
        DispatchQueue.main.async {
            if let counterValue = message["counterValue"] as? Int {
                self.counterData.append(counterValue)
                self.tableView.reloadData()
            }
        }
    }
    
    //Handlers in case the watch and phone watch connectivity session becomes disconnected
    func sessionDidDeactivate(_ session: WCSession) {}
    func sessionDidBecomeInactive(_ session: WCSession) {}
    func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {}
}

extension ViewController: UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return counterData.count;
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellIdentifier = "CounterCell"
        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
        
        let counterValueString = String(counterData[indexPath.row])
        cell?.textLabel?.text = counterValueString
        
        return cell!

    }
}
{'fraction_non_alphanumeric': 0.08794587945879459, 'fraction_numerical': 0.002050020500205002, 'mean_word_length': 2.71875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1434989', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1319, 'n_words': 339}