     }
     
     private lazy var workingFilesDirectory: URL = {
-        let urls = FileManager.default.urls(for: self.directory, in: .userDomainMask)
-        let last = urls.last!
+        let baseDirecrtory: URL
+        if let group = groupIdentifier {
+            baseDirecrtory = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group)!
+        } else {
+            let urls = FileManager.default.urls(for: self.directory, in: .userDomainMask)
+            baseDirecrtory = urls.last!
+        }
         let dbIdentifier = self.identifier + ".db"
-        let dbFolder = last.appendingPathComponent(dbIdentifier)
+        let dbFolder = baseDirecrtory.appendingPathComponent(dbIdentifier)
         do {
             try FileManager.default.createDirectory(at: dbFolder, withIntermediateDirectories: true, attributes: nil)
         } catch let error as NSError {

        }
    }
    
    public init(modelName: String, storeType: String = NSSQLiteStoreType, identifier: String = Bundle.main.bundleIdentifier!, bundle: Bundle = Bundle.main, in directory: FileManager.SearchPathDirectory = .documentDirectory, wipeOnConflict: Bool = false, sharedBackgroundContext: Bool = false) {
        stack = LegacyDataStack(modelName: modelName, type: storeType, identifier: identifier, bundle: bundle, in: directory, wipeOnConflict: wipeOnConflict, sharedBackgroundContext: sharedBackgroundContext)

        /*if #available(iOS 10, tvOS 10, *) {
            stack = CoreDataStack(modelName: modelName, type: storeType, identifier: identifier, in: directory, wipeOnConflict: wipeOnConflict)

        fatalError()
    }
    
    init(modelName: String, type: String = NSSQLiteStoreType, identifier: String, bundle: Bundle, in directory: FileManager.SearchPathDirectory = .documentDirectory, groupIdentifier: String?, mergePolicy: NSMergePolicyType = .mergeByPropertyObjectTrumpMergePolicyType, wipeOnConflict: Bool, sharedBackgroundContext: Bool) {
        
        self.modelName = modelName
        self.type = type
        self.identifier = identifier
        self.bundle = bundle
        self.directory = directory
        self.groupIdentifier = groupIdentifier
        self.mergePolicy = mergePolicy
        self.wipeOnConflict = wipeOnConflict
        self.sharedBackgroundContext = sharedBackgroundContext
