-3

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?

Kampai
  • 22,848
  • 21
  • 95
  • 95
Haloo
  • 57
  • 5

1 Answers1

-1

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)
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194