I am a digital artist, specialising in audio-visual music. And I personally think Swift is a great language for creative coding, and I wanted to hear about others' opinions. - For those who don't recognise the phrase 'creative coding', it is essentially coding for digital art. (ex. Processing, openFrameworks, C4iOS, Max/MSP/Jitter, TouchDesigner...)
Here's some pros:
Swift is an expressive language. Artist often have very specific task they need to achieve, and Swift has a lot of tools that can help them - like result builder, protocol, concurrency.
Some digital artists are not really familiar with programming, thus they tend to make unsafe programming mistakes - memory leakage, null pointer exception, data race, and so on. Swift code is inherently less vulnerable to those kind of mistakes.
Swift is fast. Some artworks like simulation work will take up a lot of CPU time and memory space. Swift is better than a lot of creative coding languages and tools out there.
But there are some obstacles too:
Cross-platform graphics / audio libraries that support Swift are rare, and often not maintained.
Apple-specific APIs like SceneKit and AudioKit are usually great, but we cannot always use Macs for displaying artwork.
Nobody uses Swift for artistic purposes. And that means there are no tutorials on how to do things.
I recently made an artwork called uncanny symmetry. It was done with Swift and SwiftUI, and it was a breeze thanks to Swift. Personally I would like to keep on using Swift for my artworks, and I am actually thinking of making cross-platform audio frameworks for Swift that behaves like SuperCollider or FAUST - if I can.
Are there anyone out there who are interested in creative coding in Swift?
I also think this is a missing space in the ecosystem. I while ago I took a stab and "porting" some concepts from Processing to Swift Processing and p5 in Swift | Alexito's World and actually got approached by multiple people that really liked the idea. There is definitely some niche for this we just need somebody to build the proper tools.
The language itself is great for this IMO, we just need some layer like p5 that makes common things more approachable. And of course multiplatform support.
I don't have much to add to this, just that I hope sooner or later this whole is filled :)
Thanks for the recommendations! SDL one looks quite promising. Unfortunately, like SkiaKit you recommended, many of the creative-coding related projects are not actively maintained. Even Apple's own SpriteKit is not really getting much attention nowadays.
That's so cool! Thanks for sharing. I have seen your video before, and I must say I was inspired.
I agree that Swift is great for creative coding, and I would very much like to continue to invest time in this field. So since I wrote the original post, I actually started to write an audio framework, and I managed to get it to output some sine wave and FM audio.
This article was my main inspiration, but I am using libsoundio / SoundIO Swift Binding to make it cross-platform. I think it is going well. Maybe I will share my progress later.
Can confirm that this works on MacOS, Linux and Windows (because as you said, I'm using it for the GUI framework).
@Jae ask me anything if the usage is unclear (there are no examples in my SkiaKit repo, but there are some in the Widgets in the VertexUI/VertexGUI repo). Just open an Issue if you want to know something.
I pushed the first alpha release of my cross-platform Swift DSP framework called Lullaby on Github!
It is far from usable, but hopefully in the future it will become something useful to people interested in computer music.
I hope you'll come and check it out, and maybe give me some feedback or tips. I am a musician first and foremost, so I don't have a lot of knowledge in DSP.
ps. I am thinking of replacing libsoundio with something more versatile, and more actively maintained. I am open for any suggestions!
ps2. On macOS, unsafe linker options has to be enabled to include C library for some reason. It is not really desirable since Xcode seems to prohibit building a project that depends on a package that has unsafe linker options. If anyone has a fix, please let me know.