"Save As" in non-document based application Cocoa "Save As" in non-document based application Cocoa unix unix

"Save As" in non-document based application Cocoa


This is pretty straightforward. You tagged this question with NSSavePanel and that's exactly what you want to use.

- (IBAction)showSavePanel:(id)sender{    NSSavePanel * savePanel = [NSSavePanel savePanel];    // Restrict the file type to whatever you like    [savePanel setAllowedFileTypes:@[@"txt"]];    // Set the starting directory    [savePanel setDirectoryURL:someURL];    // Perform other setup    // Use a completion handler -- this is a block which takes one argument    // which corresponds to the button that was clicked    [savePanel beginSheetModalForWindow:someWindow completionHandler:^(NSInteger result){        if (result == NSFileHandlingPanelOKButton) {            // Close panel before handling errors            [savePanel orderOut:self];            // Do what you need to do with the selected path        }    }];}

See also "The Save Panel" in the File System Programming Guide.