Przeglądaj źródła

check creation date (item)

Marino Faggiana 7 lat temu
rodzic
commit
9b7bb5d7cb
1 zmienionych plików z 8 dodań i 6 usunięć
  1. 8 6
      PickerFileProvider/FileProvider.swift

+ 8 - 6
PickerFileProvider/FileProvider.swift

@@ -184,13 +184,15 @@ class FileProvider: NSFileProviderExtension {
                         }
                             
                         if FileManager.default.fileExists(atPath: atPath) {
-                            
-                            let atDate = (try! FileManager.default.attributesOfItem(atPath: atPath)[FileAttributeKey.modificationDate] as! Date)
-                            let toDate = (try! FileManager.default.attributesOfItem(atPath: toPath)[FileAttributeKey.modificationDate] as! Date)
-
-                            if atDate > toDate {
+                            if FileManager.default.fileExists(atPath: toPath) {
+                                let atDate = (try! FileManager.default.attributesOfItem(atPath: atPath)[FileAttributeKey.modificationDate] as! Date)
+                                let toDate = (try! FileManager.default.attributesOfItem(atPath: toPath)[FileAttributeKey.modificationDate] as! Date)
+                                if atDate > toDate {
+                                    _ = self.copyFile(atPath, toPath: toPath)
+                                }
+                            } else {
                                 _ = self.copyFile(atPath, toPath: toPath)
-                            }                            
+                            }
                         } else {
                             FileManager.default.createFile(atPath: toPath, contents: nil, attributes: nil)
                         }