1 year ago
#208046
Wizard
Proper way to check if URL points to directory or file (uncluding FileWrapper)?
I am looking for a proper way to definitively check if an URL
points to a file or a directory. Files should include filewrapped data like UIDocument
using a FileWrapper to wrap its underlying structure.
I am aware of the fact that URLResourceValues
allows checking for isDirectory
and isRegularFile
via
let resourceValues = try? url.resourceValues(forKeys: [.isRegularFileKey, .isDirectoryKey])
resourceValues?.isDirectory
resourceValues?.isRegularFile
But in the case of a filewrapped document with a directory substructure isDirectory
would be true
but isRegularFile
would be false
, so this does not help.
The one solution I could come up with is to use documentIdentifier
like
let resourceValues = try? url.resourceValues(forKeys: [.documentIdentifierKey])
resourceValues?.documentIdentifier // non-nil if url points to file, nil otherwise
which works fine for me: documentIdentifier
is nil for a directory and non-nil for a file.
So my question is: Is using URLResourceValues
with documentIdentifier
a proper solution for checking if an URL
points to a file or a directory or is there a preferred way to do this?
ios
swift
url
uidocument
0 Answers
Your Answer