<commit_before>//
//  AppDelegate.swift
//  V
//
//  Created by <NAME> on 4/11/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit
import CoreData

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    // private optional contact importer
    private var contactImporter: ContactImporter?

    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
        
        // setup the main App context with the Main Queue Concurrency Type
        let mainContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
        
        // setup the coordinator using our CoreDataStack Singleton
        mainContext.persistentStoreCoordinator = CoreDataStack.sharedInstance.coordinator
        
        // setup a Private Dispatch Queue Context for the Contacts to work in its own thread
        let contactsContext = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType)
        // setup the persistent store coordinator for the contacts context
        contactsContext.persistentStoreCoordinator = CoreDataStack.sharedInstance.coordinator
        
        // initialize contact importer
        contactImporter = ContactImporter(context: contactsContext)
        
        // call the import contacts with this private queue context
        importContacts(contactsContext)
        
        // listen for changes
        contactImporter?.listenForChanges()
        
        // generate an instance of a tab bar controller
        let tabController = UITabBarController()
        
        // set-up an array of tuple instances of view controller data
        let vcData: [(UIViewController, UIImage)] = [
            (ContactsViewController(), UIImage(named: "contact_icon")!),
            (AllChatsViewController(), UIImage(named: "chat_icon")!)
        ]
        
        // use map closure method to create an array of UINavigationController instances
        let viewControllers = vcData.map {
            (vc: UIViewController, image: UIImage) -> UINavigationController in
            // set-up the context of each ViewController using the ContextVC Protocol
            if var vc = vc as? ContextViewController {
                vc.context = mainContext
            }
            // for each nav controller we set its root VC
            let nav = UINavigationController(rootViewController: vc)
            // and its image
            nav.tabBarItem.image = image
            // and return the NavController
            return nav
        }
        
        tabController.viewControllers = viewControllers
        window?.rootViewController = tabController
        
        return true
    }
    
    
    // MARK: Import Contacts into Core Data
    
    func importContacts(context: NSManagedObjectContext) {
        
        // check to see if we have a DataSeeded key in user defaults
        let dataSeeded = NSUserDefaults.standardUserDefaults().boolForKey("DataSeeded")
        // if we've already seeded data fall through and do not seed again
        guard !dataSeeded else { return }
        
        // fetch the user's contacts
        contactImporter?.fetch()
        
        // update user defaults with a true value for seeded data key
        NSUserDefaults.standardUserDefaults().setObject(true, forKey: "DataSeeded")
    }
}<commit_msg>Add title information to the AppDelegate vcData Array for the TabBar<commit_after>//
//  AppDelegate.swift
//  V
//
//  Created by <NAME> on 4/11/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit
import CoreData

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    // private optional contact importer
    private var contactImporter: ContactImporter?

    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
        
        // setup the main App context with the Main Queue Concurrency Type
        let mainContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
        
        // setup the coordinator using our CoreDataStack Singleton
        mainContext.persistentStoreCoordinator = CoreDataStack.sharedInstance.coordinator
        
        // setup a Private Dispatch Queue Context for the Contacts to work in its own thread
        let contactsContext = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType)
        // setup the persistent store coordinator for the contacts context
        contactsContext.persistentStoreCoordinator = CoreDataStack.sharedInstance.coordinator
        
        // initialize contact importer
        contactImporter = ContactImporter(context: contactsContext)
        
        // call the import contacts with this private queue context
        importContacts(contactsContext)
        
        // listen for changes
        contactImporter?.listenForChanges()
        
        // generate an instance of a tab bar controller
        let tabController = UITabBarController()
        
        // set-up an array of tuple instances of view controller data
        let vcData: [(UIViewController, UIImage, String)] = [
            (ContactsViewController(), UIImage(named: "contact_icon")!, "Contacts"),
            (AllChatsViewController(), UIImage(named: "chat_icon")!, "Chats")
        ]
        
        // use map closure method to create an array of UINavigationController instances
        let viewControllers = vcData.map {
            (vc: UIViewController, image: UIImage, title: String) -> UINavigationController in
            // set-up the context of each ViewController using the ContextVC Protocol
            if var vc = vc as? ContextViewController {
                vc.context = mainContext
            }
            // for each nav controller we set its root VC
            let nav = UINavigationController(rootViewController: vc)
            // its image
            nav.tabBarItem.image = image
            // and its title
            nav.title = title
            // and return the NavController
            return nav
        }
        
        tabController.viewControllers = viewControllers
        window?.rootViewController = tabController
        
        return true
    }
    
    
    // MARK: Import Contacts into Core Data
    
    func importContacts(context: NSManagedObjectContext) {
        
        // check to see if we have a DataSeeded key in user defaults
        let dataSeeded = NSUserDefaults.standardUserDefaults().boolForKey("DataSeeded")
        // if we've already seeded data fall through and do not seed again
        guard !dataSeeded else { return }
        
        // fetch the user's contacts
        contactImporter?.fetch()
        
        // update user defaults with a true value for seeded data key
        NSUserDefaults.standardUserDefaults().setObject(true, forKey: "DataSeeded")
    }
}
{'fraction_non_alphanumeric': 0.06396011396011396, 'fraction_numerical': 0.002564102564102564, 'mean_word_length': 2.325911890099479, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1031468', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1663, 'n_words': 569}