Last active
November 14, 2019 14:26
-
-
Save anupamchugh/bafdea72a505f681f07d623f62dae235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension ViewController: QLPreviewControllerDelegate { | |
| func previewController(_ controller: QLPreviewController, editingModeFor previewItem: QLPreviewItem) -> QLPreviewItemEditingMode { | |
| return .createCopy | |
| } | |
| func previewController(_ controller: QLPreviewController, didSaveEditedCopyOf previewItem: QLPreviewItem, at modifiedContentsURL: URL) { | |
| let documentsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! | |
| let currentTimeStamp = String(Int(NSDate().timeIntervalSince1970)) | |
| let destinationUrl = documentsDirectoryURL.appendingPathComponent("newFile\(currentTimeStamp).\(modifiedContentsURL.pathExtension)") | |
| if FileManager.default.fileExists(atPath: destinationUrl.path) { | |
| debugPrint("The file already exists at path") | |
| } | |
| else{ | |
| do { | |
| try FileManager.default.moveItem(at: modifiedContentsURL, to: destinationUrl) | |
| print("File moved to documents folder") | |
| } catch let error as NSError { | |
| print(error.localizedDescription) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment