<commit_before>//
//  HeroListController.swift
//  SuperDB
//
//  Created by Domenico on 31/05/15.
//  Copyright (c) 2015 Domenico. All rights reserved.
//

import UIKit
import CoreData

class HeroListController: UIViewController, UITableViewDataSource,
            UITableViewDelegate, UITabBarDelegate, NSFetchedResultsControllerDelegate {

    @IBOutlet weak var heroTableView: UITableView!
    @IBOutlet weak var heroTabBar: UITabBar!
    @IBOutlet weak var addButton: UIBarButtonItem!
    let kSelectedTabDefaultsKey = "SelectedTab"
    private var _fetchedResultsController: NSFetchedResultsController!
    
    enum tabBarKeys: Int{
        case ByName
        case BySecretIdentity
    }
    
    @IBAction func addHero(sender: UIBarButtonItem) {
        let  managedObjectContext = fetchedResultsController.managedObjectContext as NSManagedObjectContext
        let entity:NSEntityDescription = fetchedResultsController.fetchRequest.entity!
        var newHero = NSEntityDescription.insertNewObjectForEntityForName(entity.name!, inManagedObjectContext: managedObjectContext) as! NSManagedObject
        
        var error: NSError?
        
        if !managedObjectContext.save(&error) {
            let title = NSLocalizedString("Error Saving Entity", comment: "Error Saving Entity")
            let message = NSLocalizedString("Error was : \(error?.description), quitting", comment: "Error was : \(error?.description), quitting")
            
            showAlertWithCompletion(title, message:message, buttonTitle:"Ok", completion:{_ in exit(-1)})
        }
    }
    
    override func viewDidLoad() {
        // Adding the editing button
        self.navigationItem.rightBarButtonItem = self.editButtonItem()
        
        // Select the TabBar item
        let userDefaults = NSUserDefaults.standardUserDefaults()
        let selectedTab = userDefaults.integerForKey(kSelectedTabDefaultsKey)
        let item = heroTabBar.items?[selectedTab] as! UITabBarItem
        heroTabBar.selectedItem = item
        
        //Fetch any existing entities
        var error: NSError?
        if !fetchedResultsController.performFetch(&error) {
            let title = NSLocalizedString("Error Saving Entity", comment: "Error Saving Entity")<commit_msg>Performing the HeroDetail segue after the new hero has been created<commit_after>//
//  HeroListController.swift
//  SuperDB
//
//  Created by Domenico on 31/05/15.
//  Copyright (c) 2015 Domenico. All rights reserved.
//

import UIKit
import CoreData

class HeroListController: UIViewController, UITableViewDataSource,
            UITableViewDelegate, UITabBarDelegate, NSFetchedResultsControllerDelegate {

    @IBOutlet weak var heroTableView: UITableView!
    @IBOutlet weak var heroTabBar: UITabBar!
    @IBOutlet weak var addButton: UIBarButtonItem!
    let kSelectedTabDefaultsKey = "SelectedTab"
    private var _fetchedResultsController: NSFetchedResultsController!
    
    enum tabBarKeys: Int{
        case ByName
        case BySecretIdentity
    }
    
    @IBAction func addHero(sender: UIBarButtonItem) {
        let  managedObjectContext = fetchedResultsController.managedObjectContext as NSManagedObjectContext
        let entity:NSEntityDescription = fetchedResultsController.fetchRequest.entity!
        var newHero = NSEntityDescription.insertNewObjectForEntityForName(entity.name!, inManagedObjectContext: managedObjectContext) as! NSManagedObject
        
        var error: NSError?
        
        if !managedObjectContext.save(&error) {
            let title = NSLocalizedString("Error Saving Entity", comment: "Error Saving Entity")
            let message = NSLocalizedString("Error was : \(error?.description), quitting", comment: "Error was : \(error?.description), quitting")
            
            showAlertWithCompletion(title, message:message, buttonTitle:"Ok", completion:{_ in exit(-1)})
        }
        
        self.performSegueWithIdentifier("HeroDetailSegue", sender: newHero)
    }
    
    override func viewDidLoad() {
        // Adding the editing button
        self.navigationItem.rightBarButtonItem = self.editButtonItem()
        
        // Select the TabBar item
        let userDefaults = NSUserDefaults.standardUserDefaults()
        let selectedTab = userDefaults.integerForKey(kSelectedTabDefaultsKey)
        let item = heroTabBar.items?[selectedTab] as! UITabBarItem
        heroTabBar.selectedItem = item
        
        //Fetch any existing entities
        var error: NSError?
        if !fetchedResultsController.performFetch(&error) {
            let title = NSLocalizedString("Error Saving Entity", comment: "Error Saving Entity")
{'fraction_non_alphanumeric': 0.07622933218810393, 'fraction_numerical': 0.004724071290530384, 'mean_word_length': 3.1963963963963966, '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': '128215', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1211, 'n_words': 310}