NSFileManager fileExistsAtPath:isDirectory and swift

后端 未结 4 1921
悲哀的现实
悲哀的现实 2020-11-30 04:44

I\'m trying to understand how to use the function fileExistsAtPath:isDirectory: with Swift but I get completely lost.

This is my code example:

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 04:49

    Just to overload the bases. Here is mine that takes a URL

    extension FileManager {
    
        func directoryExists(atUrl url: URL) -> Bool {
            var isDirectory: ObjCBool = false
            let exists = self.fileExists(atPath: url.path, isDirectory:&isDirectory)
            return exists && isDirectory.boolValue
        }
    }
    

提交回复
热议问题