title: Prevent warning when NSDocument file is programmatically renamed
body: <p>My application allows the user to rename documents that are currently open.  This is trivial, and works fine, with one really annoying bug I can't figure out.  When a file is renamed, AppKit (kindly) warns the user the next time they try to save the document. The user says "OK" and everything continues as normal.  This makes sense when something external to the application changed the document, but not when it was actually done by the document itself.</p>
  
  <p>The code goes something like this:</p>
  
  <pre><code>-(void)renameDocumentTo:(NSString *)newName {
    NSURL *newURL = [[[self fileURL] URLByDeletingLastPathComponent]
                                     URLByAppendingPathComponent:newName];
  
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager moveItemAtURL:[self fileURL] toURL:newURL];
    NSDictionary *attrs = [fileManager attributesForItemAtPath:[newURL path] error:NULL];
  
    [self setFileURL:newURL];
    [self setFileModificationDate:[attrs fileModificationDate]];
  }
  </code></pre>
  
  <p>One would think that expressly setting the new URL and modification date on the document would be enough, but sadly it's not.  Cocoa still generates the warning.</p>
  
  <p>I've tried changing the order (setting the new URL on the document, THEN renaming the file) but this doesn't help.</p>
  
  <p>I've also tried a fix suggested by a user on an old post over at CocoaDev:</p>
  
  <pre><code>[self performSelector:@selector(_resetMoveAndRenameSensing)];
  </code></pre>
  
  <p>Even this does not stop the warning however, and I'm guessing there <em>has</em> to be a proper way to do this using the documented API.  How does Xcode handle things when a user clicks a file on the project tree and renames it to something else.  It doesn't warn the user about the rename, since the user actually performed the rename.</p>
  
  <p>What do I need to do?</p>