How to create a Save As dialogue with NSSavePanel

Likewise we can save our previously selected file using an NSSavePanel. It too is easy to use, just as the NSOpenPanel.

For a save action to make sense we need to have some data to save, so in this example we will copy an existing file (self.myURL) to the new URL that the save panel returns. We’ll let the NSFileManager just create a copy with a new name that the user specifies using the save panel:

The only alien looking thing here is the use of a Block (like it is in the NSOpenPanel). This is the equivalent to an anonymous function in JavaScript, basically a block of code that runs upon completion. As it’s part of the method call, the closing ] is way at the bottom.

Further Reading

Apple’s NSSavePanel Class Reference:

A Short Practical Guide to Blocks:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.