Firstly you call the function NSSearchPathForDirectoriesInDomains(). This function returns an array however there will almost always only be one object within the array.
NSArray
*
NSSearchPathForDirectoriesInDomains
(
NSSearchPathDirectory
directory,
NSSearchPathDomainMask
domainMask,
BOOL
expandTilde );
The reference for the method is shown above.
The Directory value must be one of the predefined search path directories of the operating system. The most commonly used directory and the one we'll use here is the documents directory which the value for is NSDocumentDirectory.
Other values can be seen in the documentation here.
The domain mask value is most often NSUserDomainMask meaning the returned path is local to the user's home directory. Other possible values are shown below.
NSUserDomainMask - Local to the user's home directory.
NSLocalDomainMask - local to the current machine.
NSNetworkDomainMask - Publicly available location in the local area network.
NSSystemDomainMask - /System (Usually unused private).
NSAllDomainsMask - will return a path for each of the above domains.
The full example of how to obtain a string of the system file path to the user documents directory is shown below.
-(NSString *)documentsDirectoryPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
return documentsDirectoryPath;
}