Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the appropriateFor parameter for in FileManager.url(for:in:appropriateFor:create:)?

Apple's instructions for creating a temporary URL are to use FileManager.url(for:in:appropriateFor:create:). The example they give is (rewritten in Swift 3):

let desktopURL = URL(fileURLWithPath: "/Users/Noah/Desktop/")
do {
    let temporaryDirectoryURL = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: desktopURL, create: true)
} catch {
    // handle error
}

The docs say that the appropriateFor parameter "determines the volume of the returned URL", but I don't understand what that means. What is this parameter for and how should I determine the URL to pass in for it?

like image 485
Noah Avatar asked May 02 '17 16:05

Noah


1 Answers

The URL that you pass in is used to determine on which Volume (on which mounted disk) the temporary directory will be created. I suspect you should pass a URL to a file or folder that would reside on the same volume.

like image 182
Scott Thompson Avatar answered Nov 02 '22 14:11

Scott Thompson