NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Customize New command with Document based SwiftUI app

Forums > SwiftUI

I want to customize the New command in a SwiftUI app based on the document app template.

It would be "fine" to simply add a drop down menu in the file search dialog that is presented. I just need to let the user select between a few "custom" (run time) types of documents. The file types are all the same, but there is a string value that lets the .init function know how to setup the document.

So, anyone have an example of how to can add a drop down menu into the dialog that lets the user pick where to create the new file either on launch or via the New menu option?

   

XCode itself might be a good template to follow?

When I tapped the New menu item in XCode, it presented 13 different options for me.

One of those (Group from selected) was enabled because I had one code file selected. If I deselected the code file, and tried New again, that option wasn't available. Sounds like what you want to achieve?

The point is, you might consider Apple's XCode as providing you a great example of how you might implement a similar feature in your cool app.

Apple's Keynote provides a different interface when you tap New. Keynote presents a dialog allowing you to select one of many themes and screen formats. If your applications is primarily document based, this might provide you an alternative design pattern.

Let us know what you decide!

   

I am built on the XCode template. I will watch the presentation and see how that is different.

I am working on an editor for authors. I have templates of various vormats - novel, shortstory, anthology, etc. I want the user to be able to pick one of the templates (they can also create their own templates, so it has to be dynamic) to create a new project. Pretty much a dumbded down, simplified use of the same thing XCode does when you can pick various from templates (iOS, MacOS, etc) to create a new project.

I originally did this using Coredata and wrote my own open dialog. I don't see in the XCode Document Template how to hook into the New command. I do NOT want to give up all the file management the Document App does for me. I just want to add options to the New command.

   

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.