I found this:
"developer.apple.com/forums/thread/119112"
which establishes the Coordinater wrapper, device and CommandQueue, etc., but how do I "replace?" those already established in ObjC code? For example, ObjC does not recognize SwiftUI struct's and I can't @objc preface a SwiftUI struct as I can a SwiftUI class(ref. the above thread).
Alternatively, is this the best venue to ask Apple to update/integrate their tutorials?
Thanks.
Code Block import SwiftUI import MetalKit struct MyMtkView: UIViewRepresentable { typealias UIViewType = MTKView var mtkView: MTKView init() { self.mtkView = MTKView() } func makeCoordinator() -> Coordinator { Coordinator(self, mtkView: mtkView) } func makeUIView(context: UIViewRepresentableContext<MyMtkView>) -> MTKView { mtkView.delegate = context.coordinator mtkView.isPaused = false mtkView.preferredFramesPerSecond = 60 mtkView.enableSetNeedsDisplay = false mtkView.framebufferOnly = true return mtkView } func updateUIView(_ uiView: MTKView, context: UIViewRepresentableContext<MyMtkView>) { // } class Coordinator : AAPLRenderer { var parent: MyMtkView init(_ parent: MyMtkView, mtkView: MTKView) { self.parent = parent guard let metalDevice = MTLCreateSystemDefaultDevice() else { fatalError("Metal is not supported on this device") } mtkView.device = metalDevice super.init(metalKitView: mtkView) mtkView.framebufferOnly = false mtkView.clearColor = MTLClearColor(red: 0, green: 0, blue: 0, alpha: 0) mtkView.drawableSize = mtkView.frame.size mtkView.enableSetNeedsDisplay = true self.mtkView(mtkView, drawableSizeWillChange: mtkView.drawableSize) } } }
You need to create a device using MTLCreateSystemDefaultDevice as in the thread you have shown
You need to initialize AAPLRenderer (Rendere?) with passing mtkView