Wednesday, August 21, 2013

iOS Tip: Getting the Path to the Documents folder


Files created by your iOS applications are usually stored in the Documents folder of your application sandbox. Often, you need to obtain the path to this folder (you cannot hard-code this during design time as this is specific to each device).

The easiest way to get the path of the Documents folder of your application is to use the NSFileManager class, like this:

- (NSURL *)applicationDocumentsDirectory
{
    return [[[NSFileManager defaultManager]
        URLsForDirectory:NSDocumentDirectory
               inDomains:NSUserDomainMask] lastObject];
}

No comments: