Newbie question: when and how to use multiple .swift files for MacOS app

I'm very new to swift. I've only been doing this for about a month.

I'm writing my first app that doesn't come from a tutorial, and I've already seen rumblings about the need to avoid dumping everything in your View Controller file. But most of the tutorials and articles I've read about how to avoid this are dealing with iOS apps with actual multiple views. Or they're just...assuming a base knowledge that I don't have yet and thus I can't make sense of them.

What I have is a single view (sort of) with a lot going on in it. And I'm not sure about the appropriate way to break it up. When I create other .swift files (even if they're subclasses of NSViewController) I can't connect my interface elements to them as @IBOutlet or @IBAction. I don't know the proper way to pass data back and forth between classes/files either.

So, for instance, the image view/well on the left, and the input/output Browse buttons and their associate text displays could be one other file, because they all deal with handling file input and/or output.

Likewise, the PopupButton (the .AAC/.M4B menu) and the two checkboxes, all deal with generating the arguments for an external process (launched by the Start Conversion button.) They could logically be in their own file/class as well.

But since the input and output data ALSO goes into constructing the arguments for the conversion process, I would need the method that creates the argument array to be able to read from the .swift file/class that manages the input/output methods, and the process launched by the Start Conversion button would need to be able to receive that array for the arguments.

I just can't figure out how to make that all happen. I managed to get some of it done by making variables global instead of local, but I'm never quite sure what class to make my new Swift files a subclass of, and I just can't find any tutorials on how to navigate this sort of situation.

Can anyone point me in the right direction?

Terms of Service

Privacy Policy

Cookie Policy