<commit_before>//
//  ViewController.swift
//  bonjour-demo-mac
//
//  Created by <NAME> on 8/05/2015.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Cocoa

class ViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource, BonjourServerDelegate {
    
    private var bonjourServer: BonjourServer!
    
    @IBOutlet private var tableView: NSTableView!
    @IBOutlet private var toSendTextField: NSTextField!
    @IBOutlet private var readLabel: NSTextField!
    @IBOutlet private var sendButton: NSButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        bonjourServer = BonjourServer()
        bonjourServer.delegate = self
    }
    
    // MARK: Bonjour server delegates
    
    func didChangeServices() {
        tableView.reloadData()
    }
    
    func connected() {
        
    }
    
    func disconnected() {
        
    }
    
    func handleBody(_ body: NSString?) {
        guard let body = body else { return }
        readLabel.stringValue = body as String
    }
    
    // MARK: TableView Delegates

    func numberOfRows(in aTableView: NSTableView) -> Int {
        return bonjourServer.devices.count
    }
    
    func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?{
        var result = ""

        let columnIdentifier = tableColumn!.identifier.rawValue
        if columnIdentifier == "bonjour-device" {
            let device = bonjourServer.devices[row]
            result = device.name
        }
        return result
    }
    
    func tableViewSelectionDidChange(_ notification: Notification) {
        print("notification: \(String(describing: notification.userInfo))")

        if bonjourServer.devices.count > 0 {
            let service = bonjourServer.devices[tableView.selectedRow]
            bonjourServer.connectTo(service)
        }<commit_msg>Use isEmpty over greater than zero<commit_after>//
//  ViewController.swift
//  bonjour-demo-mac
//
//  Created by <NAME> on 8/05/2015.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Cocoa

class ViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource, BonjourServerDelegate {
    
    private var bonjourServer: BonjourServer!
    
    @IBOutlet private var tableView: NSTableView!
    @IBOutlet private var toSendTextField: NSTextField!
    @IBOutlet private var readLabel: NSTextField!
    @IBOutlet private var sendButton: NSButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        bonjourServer = BonjourServer()
        bonjourServer.delegate = self
    }
    
    // MARK: Bonjour server delegates
    
    func didChangeServices() {
        tableView.reloadData()
    }
    
    func connected() {
        
    }
    
    func disconnected() {
        
    }
    
    func handleBody(_ body: NSString?) {
        guard let body = body else { return }
        readLabel.stringValue = body as String
    }
    
    // MARK: TableView Delegates

    func numberOfRows(in aTableView: NSTableView) -> Int {
        return bonjourServer.devices.count
    }
    
    func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?{
        var result = ""

        let columnIdentifier = tableColumn!.identifier.rawValue
        if columnIdentifier == "bonjour-device" {
            let device = bonjourServer.devices[row]
            result = device.name
        }
        return result
    }
    
    func tableViewSelectionDidChange(_ notification: Notification) {
        print("notification: \(String(describing: notification.userInfo))")

        if !bonjourServer.devices.isEmpty {
            let service = bonjourServer.devices[tableView.selectedRow]
            bonjourServer.connectTo(service)
        }
{'fraction_non_alphanumeric': 0.08670520231213873, 'fraction_numerical': 0.00604308985811876, 'mean_word_length': 2.442133815551537, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '5547597', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1040, 'n_words': 262}