<commit_before>//
//  NativePersistentContainer.swift
//  AlecrimCoreData
//
//  Created by <NAME> on 2016-10-14.
//  Copyright © 2016 Alecrim. All rights reserved.
//

import Foundation
import CoreData

// MARK: -

@available(macOSApplicationExtension 10.12, iOSApplicationExtension 10.0, tvOSApplicationExtension 10.0, watchOSApplicationExtension 3.0, *)
internal class NativePersistentContainer: NSPersistentContainer, UnderlyingPersistentContainer {
    
    private let contextType: NSManagedObjectContext.Type
    private let _viewContext: NSManagedObjectContext
    
    internal override var viewContext: NSManagedObjectContext { return self._viewContext }
    
    internal required init(name: String, managedObjectModel model: NSManagedObjectModel, contextType: NSManagedObjectContext.Type) {
        self.contextType = contextType
        self._viewContext = self.contextType.init(concurrencyType: .mainQueueConcurrencyType)
        
        super.init(name: name, managedObjectModel: model)
        
        self._viewContext.persistentStoreCoordinator = self.persistentStoreCoordinator
    }
    
    internal override func newBackgroundContext() -> NSManagedObjectContext {
        let context = self.contextType.init(concurrencyType: .privateQueueConcurrencyType)
        
        if let parentContext = self.viewContext.parent {
            context.parent = parentContext
        }
        else {
            context.persistentStoreCoordinator = self.persistentStoreCoordinator
        }

        return context
    }
    
    @available(*, unavailable)
    internal override func performBackgroundTask(_ block: @escaping (NSManagedObjectContext) -> Void) {
        fatalError()
    }

    internal var alc_persistentStoreDescriptions: [PersistentStoreDescription] {
        get { return self.persistentStoreDescriptions }
        set {
            guard let newValue = newValue as? [NSPersistentStoreDescription] else {
                fatalError("Unexpected persistent store description type.")
            }
            
            self.persistentStoreDescriptions = newValue
        }
    }
    
    internal func alc_loadPersistentStores(completionHandler block: @escaping (PersistentStoreDescription, Error?) -> Void) {
        self.loadPersistentStores(completionHandler: block)
    }
    
    internal func configureDefaults(for context: NSManagedObjectContext) {
        context.automaticallyMergesChangesFromParent = true
        context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
    }

}

// MARK: -

@available(macOSApplicationExtension 10.12, iOSApplicationExtension 10.0, tvOSApplicationExtension 10.0, watchOSApplicationExtension 3.0, *)
extension NSPersistentStoreDescription: PersistentStoreDescription {
    
}<commit_msg>Trying to make CocoaPods happy (again)<commit_after>//
//  NativePersistentContainer.swift
//  AlecrimCoreData
//
//  Created by <NAME> on 2016-10-14.
//  Copyright © 2016 Alecrim. All rights reserved.
//

import Foundation
import CoreData

// MARK: -

@available(iOS 10.0, *) // to make CocoaPods happy
@available(macOSApplicationExtension 10.12, iOSApplicationExtension 10.0, tvOSApplicationExtension 10.0, watchOSApplicationExtension 3.0, *)
internal class NativePersistentContainer: NSPersistentContainer, UnderlyingPersistentContainer {
    
    private let contextType: NSManagedObjectContext.Type
    private let _viewContext: NSManagedObjectContext
    
    internal override var viewContext: NSManagedObjectContext { return self._viewContext }
    
    internal required init(name: String, managedObjectModel model: NSManagedObjectModel, contextType: NSManagedObjectContext.Type) {
        self.contextType = contextType
        self._viewContext = self.contextType.init(concurrencyType: .mainQueueConcurrencyType)
        
        super.init(name: name, managedObjectModel: model)
        
        self._viewContext.persistentStoreCoordinator = self.persistentStoreCoordinator
    }
    
    internal override func newBackgroundContext() -> NSManagedObjectContext {
        let context = self.contextType.init(concurrencyType: .privateQueueConcurrencyType)
        
        if let parentContext = self.viewContext.parent {
            context.parent = parentContext
        }
        else {
            context.persistentStoreCoordinator = self.persistentStoreCoordinator
        }

        return context
    }
    
    @available(*, unavailable)
    internal override func performBackgroundTask(_ block: @escaping (NSManagedObjectContext) -> Void) {
        fatalError()
    }

    internal var alc_persistentStoreDescriptions: [PersistentStoreDescription] {
        get { return self.persistentStoreDescriptions }
        set {
            guard let newValue = newValue as? [NSPersistentStoreDescription] else {
                fatalError("Unexpected persistent store description type.")
            }
            
            self.persistentStoreDescriptions = newValue
        }
    }
    
    internal func alc_loadPersistentStores(completionHandler block: @escaping (PersistentStoreDescription, Error?) -> Void) {
        self.loadPersistentStores(completionHandler: block)
    }
    
    internal func configureDefaults(for context: NSManagedObjectContext) {
        context.automaticallyMergesChangesFromParent = true
        context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
    }

}

// MARK: -

@available(iOS 10.0, *) // to make CocoaPods happy
@available(macOSApplicationExtension 10.12, iOSApplicationExtension 10.0, tvOSApplicationExtension 10.0, watchOSApplicationExtension 3.0, *)
extension NSPersistentStoreDescription: PersistentStoreDescription {
    
}
{'fraction_non_alphanumeric': 0.07096204766107679, 'fraction_numerical': 0.013768755516328331, 'mean_word_length': 3.3584615384615386, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6614965', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1413, 'n_words': 321}