- (void)exportDocument:(NSString*)name toType:(NSString*)typeUTI
{
NSWindow* window = [[[self windowControllers] objectAtIndex:0] window];
// Build a new name for the file using the current name and
// the filename extension associated with the specified UTI.
CFStringRef newExtension = UTTypeCopyPreferredTagWithClass((CFStringRef)typeUTI,
kUTTagClassFilenameExtension);
NSString* newName = [[name stringByDeletingPathExtension]
stringByAppendingPathExtension:(NSString*)newExtension];
CFRelease(newExtension);
// Set the default name for the file and show the panel.
NSSavePanel* panel = [NSSavePanel savePanel];
[panel setNameFieldStringValue:newName];
[panel beginSheetModalForWindow:window completionHandler:^(NSInteger result){
if (result == NSFileHandlingPanelOKButton)
{
NSURL* theFile = [panel URL];
// Write the contents in the new format.
}
}]; }
Saving a file with a new type
最新推荐文章于 2014-08-28 14:57:51 发布