Building a Virtual Machine App on MacOS: Part 1

16-03-2025

I like to code and build projects, but finding ideas can be difficult. This week, I got the idea to build my own macOS app for running virtual machines. The inspiration came after I tried running Apple’s sample code for “running macOS in a virtual machine on Apple Silicon.” When I tested it, the virtual machine felt like a normal Mac rather than a typical virtual machine experience found in other apps.

This week, I started developing my virtual machine app. To keep the app simple, I used a NavigationSplitView in SwiftUI. I wanted to add some buttons to the toolbar located above the sidebar. However, I struggled to get this working because every time I added a button, it appeared above the toolbar in the detail view instead of the sidebar. I solved this problem by wrapping the sidebar content in a VStack and then applying the toolbar modifier to the VStack.

While building the list to display all available virtual machines, I initially implemented the highlighted virtual machine programmatically. Later, after encountering an issue with another list, I discovered that I could use the selection parameter in a SwiftUI list. This approach provided the same functionality as my custom implementation but significantly cleaned up my code.

I got into a good workflow while designing the user interface. However, this resulted in a very long file that became difficult to manage. To improve maintainability, I split the views into separate files, which greatly cleaned up my code and made it easier to work with.

Virtual machine app design preview

The current user interface of my virtual machine app is shown in the image above. In the future, the settings view will be redesigned, but first, I need to explore Apple’s documentation to learn about all the available virtualization options.

Next time, I want to learn more about the MVVM software design pattern to keep the code clean and organized. I also plan to add a working option for creating new virtual machines, as the current version relies on an array with test data.