Search code examples
iosnsfilemanager

In what circumstances would a fileReferenceURL be useful


moveItemAtURL:toURL:error

The new location for the item in srcURL. The URL in this parameter must not be a file reference URL and must include the name of the file or directory in its new location. This parameter must not be nil.

Given the above restriction, in what circumstances would a fileReferenceURL be useful?


Solution

  • fileURL is a file's path at which file is present and to access it we need to fetch that file using its fileURL.

    On the other hand fileReferenceURL points to the file directly rather than its location. So if file is moved the fileURL will change with that so we need to keep checking for fileURL if we want to access it, but fileReferenceURL will stay the same.

    According to doc about fileReferenceURL:

    A file reference URL's path should never be persistently stored, because it is not valid across system restarts or remounts of volumes

    So basically to move a file you need a path (fileURL) and not the reference of the file (fileReferenceURL).