<commit_before>//
//  ItemTableViewController.swift
//  GroceryList
//
//  Created by bearclough on 10/18/14.
//  Copyright (c) 2014 bearclough. All rights reserved.
//

import Foundation
import UIKit
import Realm

class ItemTableViewController: UITableViewController {
    
    // MARK: Properties
    var items: RLMArray
    var list: List?
    var addItemBarButtonItem: UIBarButtonItem?
    
    // MARK: Initializer
    required init(coder aDecoder: NSCoder) {
        
        if let name = list?.name {
            
            let itemPredicate = NSPredicate(format: "list.name = %@", name)
            self.items = Item.objectsWithPredicate(itemPredicate)
            
        }
            
        else {
            
            self.items = RLMArray(objectClassName: Item.className())
            
        }
        
        super.init(coder: aDecoder)
        
    }
    
    // MARK: View Life Cycle
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        // register reuse identifier for a UITableViewCell
        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "itemCell")
        
        // add plus button to nav bar
        self.addItemBarButtonItem = UIBarButtonItem(
            image: UIImage(named: "Plus"),
            style: UIBarButtonItemStyle.Plain,
            target: self,
            action: Selector("addItem"))
        
        if let addItem = self.addItemBarButtonItem {
            self.navigationItem.rightBarButtonItem = addItem
        }
        
        
    }
    
    override func viewWillAppear(animated: Bool) {
        
        super.viewWillAppear(animated)
        
    }
    
    override func viewDidAppear(animated: Bool) {
        <commit_msg>Properly saving items to realm and retrieving them for the item table view<commit_after>//
//  ItemTableViewController.swift
//  GroceryList
//
//  Created by bearclough on 10/18/14.
//  Copyright (c) 2014 bearclough. All rights reserved.
//

import Foundation
import UIKit
import Realm

class ItemTableViewController: UITableViewController {
    
    // MARK: Properties
    var items: RLMArray
    var list: List?
    var addItemBarButtonItem: UIBarButtonItem?
    
    // MARK: Initializer
    required init(coder aDecoder: NSCoder) {
            
        self.items = RLMArray(objectClassName: Item.className())
        
        super.init(coder: aDecoder)
        
    }
    
    // MARK: View Life Cycle
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        // register reuse identifier for a UITableViewCell
        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "itemCell")
        
        // add plus button to nav bar
        self.addItemBarButtonItem = UIBarButtonItem(
            image: UIImage(named: "Plus"),
            style: UIBarButtonItemStyle.Plain,
            target: self,
            action: Selector("addItem"))
        
        if let addItem = self.addItemBarButtonItem {
            self.navigationItem.rightBarButtonItem = addItem
        }
        
        // populate list of items b/c this is never called in init
        if let name = list?.name {
            
            let itemPredicate = NSPredicate(format: "list.name = %@", name)
            self.items = Item.objectsWithPredicate(itemPredicate)
            
        }
        
        
    }
    
    override func viewWillAppear(animated: Bool) {
        
        super.viewWillAppear(animated)
        
    }
    
    override func viewDidAppear(animated: Bool) {
        
{'fraction_non_alphanumeric': 0.07872044506258692, 'fraction_numerical': 0.005563282336578581, 'mean_word_length': 1.8028059236165237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1775533', 'n_tokens_mistral': 1038, 'n_tokens_neox': 993, 'n_words': 236}