Created
October 16, 2019 14:31
-
-
Save andrewwoz/3fda6be2560cd9edd0b6b3b6fd0a4257 to your computer and use it in GitHub Desktop.
[Replace item(file)] #fs
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
| let fs = FileManager.default | |
| let docsURL = ... | |
| // create first test file | |
| let newFile = docs.appendingPathComponent("newFile.txt") | |
| fs.createFile( | |
| atPath: newFile.path, | |
| contents: ..., | |
| attributes: nil) | |
| // create second test file | |
| let fileToReplace = docs.appendingPathComponent("fileToReplace.txt") | |
| fs.createFile( | |
| atPath: fileToReplace.path, | |
| contents: ..., | |
| attributes: nil) | |
| try? fs.replaceItem( | |
| at: fileToReplace, | |
| withItemAt: newFile, | |
| backupItemName: "contentOfOldFile.txt", | |
| options: .withoutDeletingBackupItem, | |
| resultingItemURL: nil | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment