             
             logInfo(tag) { "Attaching persistent store \"\(storeURL.lastPathComponent ?? "Unknown")\" for type: \(persistentStoreType)."}
 
-            if options?[CCOverwriteIncompatibleStoreOption] as? Bool == true {
-                
-                let fileManager = NSFileManager.defaultManager()
-                
-                if let path = storeURL.path where fileManager.fileExistsAtPath(path) {
+            let fileManager = NSFileManager.defaultManager()
+            
+            if let storePath = storeURL.path where fileManager.fileExistsAtPath(storePath) {
+                
+                let storeShmPath = "\(storePath)-shm"
+                let storeWalPath = "\(storePath)-wal"
+                
+                if let requiredProtection = options?[NSPersistentStoreFileProtectionKey] as? String {
+                    //
+                    // If the file protection bit is different than the require protection
+                    // type, we reset the protection.
+                    //
+                    // Note: this must be done before opening the data store either with 
+                    //       metadataForPersistentStoreOfType or normally with
+                    //       addPersistentStoreWithType.
+                    //
+                    try updateFileProtectionIfNeeded(storePath,    requiredProtection: requiredProtection)
+                    try updateFileProtectionIfNeeded(storeShmPath, requiredProtection: requiredProtection)
+                    try updateFileProtectionIfNeeded(storeWalPath, requiredProtection: requiredProtection)
+                }
+                
+                // Check the store for compatibility if requested by developer.
+                if options?[CCOverwriteIncompatibleStoreOption] as? Bool == true {
                     
                     logInfo(tag) { "Checking to see if persistent store is compatible with the model." }
-
+                    
                     let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStoreOfType(storeType, URL: storeURL, options: nil)
                     logTrace(4) { "metadata: \(metadata)" }
-
+                    
                     if !persistentStoreCoordinator.managedObjectModel.isConfiguration(configuration, compatibleWithStoreMetadata: metadata) {
                         
-                        logInfo(tag) { "Attempting to remove file \(storeURL) and -shm and -wal files" }
-                        
-                        try deleteIfExists(fileURL: storeURL)
-                        try deleteIfExists(fileURL: NSURL(fileURLWithPath: "\(path)-shm"))
-                        try deleteIfExists(fileURL: NSURL(fileURLWithPath: "\(path)-wal"))
+                        try deleteIfExists(storePath)
+                        try deleteIfExists(storeShmPath)
+                        try deleteIfExists(storeWalPath)
                     }
                 }
             }
+            
             logInfo(tag) { "Attaching new persistent store \"\(storeURL.lastPathComponent ?? "Unknown")\" for type: \(persistentStoreType)."}
             
             try persistentStoreCoordinator.addPersistentStoreWithType(storeType, configuration:  configuration, URL: storeURL, options: options)

        }
    }
    
    private func deleteIfExists(fileURL url: NSURL) throws {
        
        let fileManager = NSFileManager.defaultManager()
        
        if let path = url.path {
            if fileManager.fileExistsAtPath(path) {
                try fileManager.removeItemAtURL(url)
            }
        }
    }

    NSIgnorePersistentStoreVersioningOption         : true,
    NSMigratePersistentStoresAutomaticallyOption    : true,
    NSInferMappingModelAutomaticallyOption          : true,
    NSPersistentStoreFileProtectionKey              : NSFileProtectionCompleteUntilFirstUserAuthentication
]

/**
