这怎么可能?
let exists = NSFileManager.defaultManager().fileExistsAtPath(path.absoluteString)
print("exists: \(exists)") //false
Run Code Online (Sandbox Code Playgroud)
这是 path.absoluteString
//file:///Users/kuna/Library/Developer/CoreSimulator/Devices/92BD140D-5C14-43C4-80D6-904BB9594ED6/data/Containers/Data/Application/5B818832-BB19-4047-A7F8-1487F36868D6/Documents/wishlists/68/147/128/IMG_0006.PNG
Run Code Online (Sandbox Code Playgroud)
你可以看到它应该在哪里:
到底是怎么回事?
当我使用方法.fileExists(atPath:)来判断文件是否存在于文件系统中时,该方法总是向我返回false.我检查了文件系统,文件确实存在.这是我的代码:
let filePath = url?.path
var isDir : ObjCBool = false
if(self.fileManager.fileExists(atPath: filePath!, isDirectory: &isDir)){
let result = NSData(contentsOfFile: filePath!)
}
Run Code Online (Sandbox Code Playgroud)
要么
let filePath = url?.path
if(self.fileManager.fileExists(atPath: filePath!)){
let result = NSData(contentsOfFile: filePath!)
}
Run Code Online (Sandbox Code Playgroud)
始终会跳过if子句.