Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should never, ever, hard-code paths. You should construct your paths using the <a href="https://developer.apple.com/library/mac/documentation/cocoa/conceptual/strings/Articles/ManipulatingPaths.html#//apple_ref/doc/uid/20000152-BBCBIGHH" rel="nofollow">various APIs</a> available to do so.</p> <p>There are several ways to construct valid paths. For instance, this works:</p> <pre><code>NSString* filePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"] stringByAppendingPathComponent:@"CustomerNames.plist"]; </code></pre> <p>Alternatively, you could use:</p> <pre><code>NSString* filePath = [@"~/Desktop/CustomerNames.plist" stringByExpandingTildeInPath]; </code></pre> <p>Although these are correct ways to build a path, to access special locations such as the Desktop, the Documents folder or the Application Support folder, you should use the <a href="https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/miscellaneous/foundation_functions/Reference/reference.html#//apple_ref/doc/uid/20000055-SW5" rel="nofollow"><code>NSSearchPathForDirectoriesInDomains()</code></a> function or, preferably, the <code>NSFileManager</code> methods <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsfilemanager_Class/Reference/Reference.html#//apple_ref/doc/uid/20000305-SW102" rel="nofollow"><code>URLsForDirectory:inDomains:</code></a> or <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsfilemanager_Class/Reference/Reference.html#//apple_ref/doc/uid/20000305-SW101" rel="nofollow"><code>URLForDirectory:inDomain:appropriateForURL:create:error:</code></a>.</p> <p>These URL-based method should always be preferred over their path-based equivalents. Apple recommends all developers move to support the URL-based methods as soon as practicable.</p> <p>This is primarily because file URLs can store bookmark data, so that if a file moves the URL can still be resolved, which is not the case with paths as paths are just strings and can't store metadata.</p> <p>Here's how you'd use the file manager to find your URL:</p> <pre><code>NSFileManager* fm = [NSFileManager defaultManager]; NSURL* desktopURL = [fm URLForDirectory:NSDesktopDirectory inDomain:NSUserDomainMask appropriateForURL:nil shouldCreate:NO error:nil]; NSURL* fileURL = [desktopURL URLByAppendingPathComponent:@"CustomerNames.plist"]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload