Last active
June 4, 2024 22:33
-
-
Save benigumocom/20204419c4bc33eba2294c97f62cbd30 to your computer and use it in GitHub Desktop.
【Swift】その URL が ファイル なのか ディレクトリ なのか 存在しないのか 👉 https://android.benigumo.com/20240605/resource-values/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension URL { | |
// private var resourceIsDirectory: Bool? { | |
// (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory | |
// } | |
var exists: Bool { | |
// resourceIsDirectory != nil | |
// (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory != nil | |
// (try? resourceValues(forKeys: [.isRegularFileKey]))?.isRegularFile != nil | |
isFile || isDirectory | |
} | |
var isFile: Bool { | |
// resourceIsDirectory == false | |
// (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == false | |
(try? resourceValues(forKeys: [.isRegularFileKey]))?.isRegularFile == true | |
} | |
var isDirectory: Bool { | |
// resourceIsDirectory == true | |
// (try? resourceValues(forKeys: [.isRegularFileKey]))?.isRegularFile == false | |
(try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment