I made "collectionView reorder by using drag feature". I drag file and need to change its name on the disk to make reorder.
How can I swap file names for 2 files?
I made "collectionView reorder by using drag feature". I drag file and need to change its name on the disk to make reorder.
How can I swap file names for 2 files?
Obviously, use temporary file:
var tempFileURL: URL {
let tmpDirURL = Filemanager.default
let tmpFilename = UUID().uuidString
let tmpFileURL = tmpDirURL.appendingPathComponent(tmpFilename)
return tmpFileURL
}
After that just move:
let temp = FileManager.default.tempFileURL
try FileManager.default.moveItem(at: first, to: temp)
try FileManager.default.moveItem(at: second, to: first)
try FileManager.default.moveItem(at: temp, to: second)