Metal Sample Code in Swift?

I've noticed that all of the sample Metal code I've downloaded, from the basic "Creating and Sampling from Textures" to "Modern Rendering with Metal," are all written in Objective-C. I'm hopeful someday one of the demo projects will be written in Swift since that's what I've used to write my Metal apps and I'm looking for some interesting uses of the Swift language as it relates to working with Metal. I understand the Objective-C provided but it would be neat if the samples were written in Swift.

Will there ever be a sample project in Swift that uses Metal?Perhaps released with WWDC 2021?
Answered by Graphics and Games Engineer in 676867022

There are a number of reasons why most of the Metal samples are written in Objective-C and not Swift, probably the most important of which is that most game developers prefer C++ and, although Objective-C is not their ideal choice, Swift is non-starter for them.

That said, we do have a handful of Metal samples written with Swift. This version of the Rendering a Scene with Deferred Lighting is written in Swift (and there are separate downloads for Objective-C and C++ versions). The Supporting Simulator in a Metal App sample has both Swift and Objective-C versions in the same download.

Here, there are objC and Swift sample code

https://developer.apple.com/documentation/metal/modern_rendering_with_metal

But may be not what you are looking for.

If you really have a problem, you should file a bug report.

I don't understand why Apple Engineers keep preferring Objective-C for sample code. I presume they think most people are still using it, but at my employer we converted to Swift years ago. Translating things mentally from Obj-C to Swift is now difficult because I haven't used it in years, and Swift is where most of the iOS/MacOS market is today. Back when I worked at Apple in the mid 90's we still had some sample code in Pascal, which made just as much sense, i.e. none.

Maybe things will improve in WWDC 21.

Accepted Answer

There are a number of reasons why most of the Metal samples are written in Objective-C and not Swift, probably the most important of which is that most game developers prefer C++ and, although Objective-C is not their ideal choice, Swift is non-starter for them.

That said, we do have a handful of Metal samples written with Swift. This version of the Rendering a Scene with Deferred Lighting is written in Swift (and there are separate downloads for Objective-C and C++ versions). The Supporting Simulator in a Metal App sample has both Swift and Objective-C versions in the same download.

Metal Sample Code in Swift?
 
 
Q