iosobjective-cnsfilemanager

How to remove a directory and its contents using NSFileManager


I have created a few directories which contain PDF files for an iOS app. How can I delete a directory and its contents using NSFileManager?

Do I need to loop through and remove the contents first? Any code samples would be much appreciated.


Solution

  • To start off, it would be wise to look through Apple's NSFileManager documentation: NSFileManager Class Reference. Second, look at NSFileManager's -removeItemAtPath:error: method and its documentation. That's what you're looking for.