I submitted an app written in SwiftUI to the App Store yesterday. It was the most infuriating, hair pulling, head banging-against-the-wall experience of my life. Also, maybe Swift really is the best language?

Let me rewind a bit. Three years ago I came across this idea called Fractal Music Composition. Basically you take the 8 letters of the musical alphabet — A, B, C, D, E, F and G, map each to another sequence of these 8 letters, take a starting sequence of letters and recursively replace each letter with it’s mapped sequence for as many iterations as you want.

Now you have a musical composition :)

As an iPhone developer, I thought it would be fun to write up a little app that could do this and play it back to you. I called it ‘Fractalator’.

It um…looked really bad. Thankfully I didn’t save a picture.

I also switched out the random Google Image I was using as an icon for this handcrafted, minimalist expression of the fundamental experience of mathematics as applied to music

I never got around to publishing to the App Store at the time, there was still a few kinks to be worked out. Then I went back to school and pretty much forgot about it anyway.

Fast forward to a month ago. With lots of free time and some recently acquired SwiftUI knowledge from Apple’s free tutorials I decided it could be fun to refactor Fractalator into a SwiftUI app. This turned out to be really easy! Fortunately, the app was small — I was able to complete the conversion in a single afternoon.

1183 lines of code removed — this app had a lot of bloat!

Some highlights:

Almost 1200 lines of code removed — a 68.7% reduction The app looked a LOT nicer I switched out the audio processing code I was using from CoreMidi to AudioToolbox making the audio code much easier to understand Writing everything in SwiftUI is just so…declarative!

The SwiftUI app has three screens. From left to right: see all the details of your fractal, enter the details of your rule or seed and see the full “fractalized” composition while it plays for you in all its MIDI glory (maybe could look nicer!).

I created a struct called Score that held the details of what sequence would replace which letter, what the starting seed was, how many iterations to conduct and what the final creation was. Then I passed an instance of this as an @State variable to my MainView . This made it really easy to use @Binding to bind the values of the rows to their appropriate sequence. For the number of iterations, a simple Stepper did the job perfectly.

SF Symbols provided the little pencil icons that give users the cue to tap a row to edit it. Some simple padding and borders gave the phone keypad-looking letter entry modal its signature look.