Cocoa - NSFileManager removeItemAtPath Not Working

前端 未结 6 617
再見小時候
再見小時候 2021-01-21 04:03

I am trying to delete a file, but somehow nsfilemanager will not allow me to do so. I do use the file in one line of code, but once that action has been ran, I want the file del

6条回答
  •  终归单人心
    2021-01-21 05:06

    I just figure it out of something very important when you use NSFileManager. You have to be aware of App Sandboxing.

    let documentDirectory = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, .UserDomainMask, true)[0]
    

    This line return the path document directory of your app sandboxed. When you create a file with FileManager in your document directory (for e.g) don't save the full file path but only the path from the current document directory.

    You'll be able to recreate the full path of your created file.

    Hope (after 5 years) help over developers ;-)

提交回复
热议问题