<commit_before>//
//  TaskListViewController.swift
//  Todobox
//
//  Created by 전수열 on 12/26/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

let TodoboxTasksUserDefaultsKey = "TodoboxTasksUserDefaultsKey"

class TaskListViewController: UIViewController {

    @IBOutlet var tableView: UITableView!

    /// 할 일 목록
    var tasks = [Task]()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.loadAll()

        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if let navigationController = segue.destinationViewController as? UINavigationController,
           let taskEditorViewController = navigationController.viewControllers.first as? TaskEditorViewController {
            taskEditorViewController.didAddHandler = { task in
                self.tasks.append(task)
                self.saveAll()
                self.tableView.reloadData()
            }
        }
    }

    /// `tasks`를 로컬에 저장합니다.
    func saveAll() {
        let data = self.tasks.map {
            [
                "title": $0.title,
                "done": $0.done,
            ]
        }

        let userDefaults = NSUserDefaults.standardUserDefaults()
        userDefaults.setObject(data, forKey: TodoboxTasksUserDefaultsKey)
        userDefaults.synchronize()
    }

    func loadAll() {
        let userDefaults = NSUserDefaults.standardUserDefaults()
        guard let data = userDefaults.objectForKey(TodoboxTasksUserDefaultsKey) as? [[String: AnyObject]] else {
            return
        }

        self.tasks = data.flatMap {
            guard let title = $0["title"] as? String else {
                return nil
            }
            let done = $0["done"]?.boolValue == true
            return Task(title: title, done: done)
        }
    }

    @IBAction func editButtonDidTap() {

    }

}


// MARK: - UITableViewDataSource

extension TaskListViewController: UITableViewDataSource {

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.tasks.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell")!
        let task = self.tasks[indexPath.row]
        cell.textLabel?.text = task.title
        if task.done {
            cell.accessoryType = .Checkmark
        } else {
            cell.accessoryType = .None
        }
        return cell
    }

}


// MARK: - UITableViewDelegate

extension TaskListViewController: UITableViewDelegate {

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        var task = self.tasks[indexPath.row]
        task.done = !task.done
        self.tasks[indexPath.row] = task
        self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
    }

}
<commit_msg>editButton 속성 추가<commit_after>//
//  TaskListViewController.swift
//  Todobox
//
//  Created by 전수열 on 12/26/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

let TodoboxTasksUserDefaultsKey = "TodoboxTasksUserDefaultsKey"

class TaskListViewController: UIViewController {

    @IBOutlet var tableView: UITableView!
    @IBOutlet var editButton: UIBarButtonItem!

    /// 할 일 목록
    var tasks = [Task]()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.loadAll()

        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if let navigationController = segue.destinationViewController as? UINavigationController,
           let taskEditorViewController = navigationController.viewControllers.first as? TaskEditorViewController {
            taskEditorViewController.didAddHandler = { task in
                self.tasks.append(task)
                self.saveAll()
                self.tableView.reloadData()
            }
        }
    }

    /// `tasks`를 로컬에 저장합니다.
    func saveAll() {
        let data = self.tasks.map {
            [
                "title": $0.title,
                "done": $0.done,
            ]
        }

        let userDefaults = NSUserDefaults.standardUserDefaults()
        userDefaults.setObject(data, forKey: TodoboxTasksUserDefaultsKey)
        userDefaults.synchronize()
    }

    func loadAll() {
        let userDefaults = NSUserDefaults.standardUserDefaults()
        guard let data = userDefaults.objectForKey(TodoboxTasksUserDefaultsKey) as? [[String: AnyObject]] else {
            return
        }

        self.tasks = data.flatMap {
            guard let title = $0["title"] as? String else {
                return nil
            }
            let done = $0["done"]?.boolValue == true
            return Task(title: title, done: done)
        }
    }

    @IBAction func editButtonDidTap() {
    }

}


// MARK: - UITableViewDataSource

extension TaskListViewController: UITableViewDataSource {

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.tasks.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell")!
        let task = self.tasks[indexPath.row]
        cell.textLabel?.text = task.title
        if task.done {
            cell.accessoryType = .Checkmark
        } else {
            cell.accessoryType = .None
        }
        return cell
    }

}


// MARK: - UITableViewDelegate

extension TaskListViewController: UITableViewDelegate {

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        var task = self.tasks[indexPath.row]
        task.done = !task.done
        self.tasks[indexPath.row] = task
        self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
    }

}

{'fraction_non_alphanumeric': 0.09158995163051958, 'fraction_numerical': 0.004368856295833983, 'mean_word_length': 2.366596638655462, 'pattern_counts': {'":': 4, '<': 5, '<?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': '2870477', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1780, 'n_words': 388}