Flipkart Search

Search This Blog

Friday, September 11, 2009

find the documents directory on the iPhone in Just One Line Code

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 application 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-line of code for you to use in your applications.

[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/YourDatabaseFileNameWithExtension"];

Here is the old method i was using before i found this on icodeblog.com...thanks to Brandon.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *MyDatabasePath = [documentsDirectory stringByAppendingString:@"/YourDatabaseFileNameWithExtension"];

1 comment:

StevenHWicker said...

This is a really informative knowledge, Thanks for posting this informative Information. Apple Developer Login