     }
     
     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 {

    fileprivate let identifier: String
    fileprivate let bundle: Bundle
    private let directory: FileManager.SearchPathDirectory
    fileprivate let mergePolicy: NSMergePolicyType
    fileprivate let wipeOnConflict: Bool
    fileprivate let sharedBackgroundContext: Bool

        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
