0

I would like my OS X app to open a sample document located in the application bundle.

I'm currently doing the following:

NSString* path = [[NSBundle mainBundle] pathForResource:@"tutorial.doc" ofType:nil];
[_documentController openDocumentWithContentsOfURL:[NSURL fileURLWithPath:path] display:YES completionHandler:nil];

This works but has an unexpected effect: if I make changes to the document and save, the next time I open the bundle document the changes persist. I expected the bundle document to be read-only.

What am I doing wrong? How can I prevent this sample document to be modified?

hpique
  • 119,096
  • 131
  • 338
  • 476

1 Answers1

0

You can use the duplicateDocumentWithContentsOfURL:copying:displayName:error: method instead. This creates a copy of the document the user can play with (and save to some other location if he wants to). This method is available only on OS X 10.7 or later though.

Sven
  • 22,475
  • 4
  • 52
  • 71
  • This is useful but I would prefer to avoid making a copy of the document, mostly because when the user closes the document he's prompted to save the copy. Isn't there a way to say, "don't save this document"? – hpique Sep 27 '12 at 18:09