SwiftUI + Metal

is there a complete tutorial or example on how to integrate Metal with SwiftUI? There only seems to be some scattered questions and answers around the web about this subject.

Replies

Hi, SwiftUI is very high level and Metal is very low level, so you need some middle ground.
In short you can wrap a MTKView in a UIViewRepresentable, tho you need to setup a render pipeline.
I would start by looking through some Metal Sample Code to get started.
There is a prior post, "MetalKit in SwiftUI", thread/119112 (or just click here) where someone asked a similar question and there was a partial answer, with an incomplete code sample. It seems to be a good start at the very least. It's something I'm interested in doing as well tho!
  • Are there any examples of using metal with swiftUI on macOS rather than iOS?

    Thanks

Add a Comment
What kind of sample project(s) did you have in mind?
Other than essential integration what would you be looking to learn?
https://developer.apple.com/forums/thread/119112 now has a working standalone code snippet