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?
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.