Code Snippet – Quickly Find The Documents Directory

September 9th, 2009 Posted by: - posted under:Snippets

As many of you may have seen by now, there are quite a few ways to find the documents directory on the iPhone. For those of you who don’t know, the documents directory of an app is the location where you should save your application data. While finding the documents directory is a trivial task, it is very important when coding most applications. Apple has provided quite a few ways for resolving the path to this directory.

If you read through some of Apple’s sample code, you will see their code to do this is generally 3 or 4 lines long. This seems like a lot of code to perform such a simple task. Here is a nice one-liner for you to use in your applications.

NSString * docs = [NSHomeDirectory()
						   stringByAppendingPathComponent:@"Documents"];

It’s clean and concise. Happy iCoding!