<commit_before>//
//  AppDelegate.swift
//  DDDViewDataExample
//
//  Created by <NAME> on 16.11.14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Cocoa

let kErrorDomain = "DDDViewDataExampleErrorDomain"

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    
    func notificationCenter() -> NSNotificationCenter {
        return NSNotificationCenter.defaultCenter()
    }
    
    lazy var persistentStack: PersistentStack = {
        let storeURL = self.applicationDocumentsDirectory.URLByAppendingPathComponent("ItemModel.sqlite");
        let modelURL = NSBundle.mainBundle().URLForResource(kDefaultModelName, withExtension: "momd")
        
        let persistentStack = PersistentStack(storeURL: storeURL, modelURL: modelURL!)
        
        self.notificationCenter().addObserver(persistentStack, selector: "objectContextWillSave", name: NSManagedObjectContextWillSaveNotification, object: persistentStack.managedObjectContext)
        
        return persistentStack
    }()

    lazy var applicationDocumentsDirectory: NSURL = {
        // The directory the application uses to store the Core Data store file. This code uses a directory named "de.christiantietze.DDDViewDataExample" in the user's Application Support directory.
        let urls = NSFileManager.defaultManager().URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)
        let appSupportURL = urls[urls.count - 1] as NSURL
        let directory = appSupportURL.URLByAppendingPathComponent("de.christiantietze.DDDViewDataExample")
        
        self.guardApplicationDocumentsDirectory(directory)
        
        return directory
    }()
    
    private func guardApplicationDocumentsDirectory(directory: NSURL) {
        // Make sure the application files directory is there
        var error: NSError? = nil
        var success: Bool = true
        let propertiesOpt = directory.resourceValuesForKeys([NSURLIsDirectoryKey], error: &error)
        
        if let properties = propertiesOpt {
            if let isDirectory = properties[NSURLIsDirectoryKey]!.boolValue {
                return
            }
            
            let userInfo = NSMutableDictionary()
            userInfo[NSLocalizedDescriptionKey] = "Failed to initialize the persistent stack"
            userInfo[NSLocalizedFailureReasonErrorKey] = "Expected a folder to store application data, found a file \(self.applicationDocumentsDirectory.path)."
            
            if error != nil {
                userInfo[NSUnderlyingErrorKey] = error
            }
            
            error = NSError(domain: kErrorDomain, code: 1, userInfo: userInfo)
            success = false
        } else if error!.code == NSFileReadNoSuchFileError {
            let fileManager = NSFileManager.defaultManager()
            if fileManager.createDirectoryAtPath(self.applicationDocumentsDirectory.path!, withIntermediateDirectories: true, attributes: nil, error: &error) {
                return
            }
            
            let userInfo = NSMutableDictionary()
            userInfo[NSLocalizedDescriptionKey] = "Failed to create the application documents directory"
            userInfo[NSLocalizedFailureReasonErrorKey] = "Creation of \(self.applicationDocumentsDirectory.path) failed."
            
            if error != nil {
                userInfo[NSUnderlyingErrorKey] = error
            }
            
            error = NSError(domain: kErrorDomain, code: 1, userInfo: userInfo)
            success = false
        }
        
        if !success {
            NSApplication.sharedApplication().presentError(error!)
            
            abort()<commit_msg>resolve inf. recursion<commit_after>//
//  AppDelegate.swift
//  DDDViewDataExample
//
//  Created by <NAME> on 16.11.14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Cocoa

let kErrorDomain = "DDDViewDataExampleErrorDomain"

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    
    func notificationCenter() -> NSNotificationCenter {
        return NSNotificationCenter.defaultCenter()
    }
    
    lazy var persistentStack: PersistentStack = {
        let storeURL = self.applicationDocumentsDirectory.URLByAppendingPathComponent("ItemModel.sqlite");
        let modelURL = NSBundle.mainBundle().URLForResource(kDefaultModelName, withExtension: "momd")
        
        let persistentStack = PersistentStack(storeURL: storeURL, modelURL: modelURL!)
        
        self.notificationCenter().addObserver(persistentStack, selector: "objectContextWillSave", name: NSManagedObjectContextWillSaveNotification, object: persistentStack.managedObjectContext)
        
        return persistentStack
    }()

    lazy var applicationDocumentsDirectory: NSURL = {
        // The directory the application uses to store the Core Data store file. This code uses a directory named "de.christiantietze.DDDViewDataExample" in the user's Application Support directory.
        let urls = NSFileManager.defaultManager().URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)
        let appSupportURL = urls[urls.count - 1] as NSURL
        let directory = appSupportURL.URLByAppendingPathComponent("de.christiantietze.DDDViewDataExample")
        
        self.guardApplicationDocumentsDirectory(directory)
        
        return directory
    }()
    
    private func guardApplicationDocumentsDirectory(directory: NSURL) {
        // Make sure the application files directory is there
        var error: NSError? = nil
        var success: Bool = true
        let propertiesOpt = directory.resourceValuesForKeys([NSURLIsDirectoryKey], error: &error)
        
        if let properties = propertiesOpt {
            if let isDirectory = properties[NSURLIsDirectoryKey]!.boolValue {
                return
            }
            
            let userInfo = NSMutableDictionary()
            userInfo[NSLocalizedDescriptionKey] = "Failed to initialize the persistent stack"
            userInfo[NSLocalizedFailureReasonErrorKey] = "Expected a folder to store application data, found a file \(self.applicationDocumentsDirectory.path)."
            
            if error != nil {
                userInfo[NSUnderlyingErrorKey] = error
            }
            
            error = NSError(domain: kErrorDomain, code: 1, userInfo: userInfo)
            success = false
        } else if error!.code == NSFileReadNoSuchFileError {
            let fileManager = NSFileManager.defaultManager()
            if fileManager.createDirectoryAtPath(directory.path!, withIntermediateDirectories: true, attributes: nil, error: &error) {
                return
            }
            
            let userInfo = NSMutableDictionary()
            userInfo[NSLocalizedDescriptionKey] = "Failed to create the application documents directory"
            userInfo[NSLocalizedFailureReasonErrorKey] = "Creation of \(self.applicationDocumentsDirectory.path) failed."
            
            if error != nil {
                userInfo[NSUnderlyingErrorKey] = error
            }
            
            error = NSError(domain: kErrorDomain, code: 1, userInfo: userInfo)
            success = false
        }
        
        if !success {
            NSApplication.sharedApplication().presentError(error!)
            
            abort()
{'fraction_non_alphanumeric': 0.0738327904451683, 'fraction_numerical': 0.003528773072747014, 'mean_word_length': 2.5754488112566714, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3501177', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1759, 'n_words': 447}