How to check if a file exists in Documents folder?

后端 未结 7 1392
小蘑菇
小蘑菇 2020-11-29 14:53

I have an application with In-App Purchase, that when the user buy something, download one html file into the Documents folder of my app.

Now I must check if this HT

7条回答
  •  暖寄归人
    2020-11-29 15:36

    Swift 2.0

    This is how to check if the file exists using Swift

    func isFileExistsInDirectory() -> Bool {
        let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
        let documentsDirectory: AnyObject = paths[0]
        let dataPath = documentsDirectory.stringByAppendingPathComponent("/YourFileName")
    
        return NSFileManager.defaultManager().fileExistsAtPath(dataPath)
    }
    

提交回复
热议问题