title: When should I use NSURL instead of NSString and vice versa?
body: <p>This is not a question about a pertinent problem. It's a question by which I try to deepen my understanding of Objective-C or more specific Cocoa Foundation.</p>
  
  <p>When dealing with uploading and download files from a server to my apps, I'm constantly torn between using <code>NSURL</code> or <code>NSString</code> for all things path related. Of course when there's an existing API I just use it according to the specs. But when I store my own paths or create custom classes that deal with them, I'm confused which of the two would be the better pick.</p>
  
  <p><code>NSString</code> is used everywhere and it has convenience methods like <code>stringByAppendingPathComponent:</code> and <code>stringByAppendingPathExtension:</code>. I can easily convert to NSURL by creating a new instance with <code>[NSURL URLWithString:@"string"]</code> and the other way around by calling <code>[url path]</code> on an NSURL instance. But the difference is there for a reason, right?</p>
  
  <p>My confusion grows when I look at header files of something like NSFileManager. These two methods are pretty close together:</p>
  
  <pre><code>- (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error;
  - (BOOL)copyItemAtURL:(NSURL *)srcURL toURL:(NSURL *)dstURL error:(NSError **)error NS_AVAILABLE(10_6, 4_0);
  </code></pre>
  
  <p>Why would I choose to use one over the other, especially when conversions between the two are made so easily? And why does Apple go through the trouble of creating near-identical APIs for using both data types?</p>
  
  <p>If someone has the deeper insight for when to use NSURL instead of NSString for your own classes handling file paths and remote urls, please do share! Cheers.</p>