Here's a short but complete bit of code that only attempts to do one thing, but never even gets to the point that it can compile. It merely tries to set the name of one of the attributes of a MDLVertexDescriptor. The attributes are read-only, though I'm not trying to mutate the array of attributes, merely a property of one of them, like so:
import MetalKit
let x = MTLVertexDescriptor()
var y = MTKModelIOVertexDescriptorFromMetal(x)
var a = y.attributes
var a0 = a[0]
a0.name = MDLVertexAttributeNormal
The last line is rejected because a0 is immutable. You can try to set y.attributes[0].name in one go, but that'll fail too. It seems like it's just my bad, trying to mutate a read-only property, something Swift strictly enforces, but this a just a direct translation of the following Objective-C code that does work (used in, e.g., MetalKitEssentials):
MDLVertexDescriptor *y = MTKModelIOVertexDescriptorFromMetal(x);
y.attributes[0].name = MDLVertexAttributePosition;
(What makes it a bit more disconcerting is that while the docs say that attributes are read-only, the header declaration has it listed as "var attributes: NSMutableArray" which sounds pretty mutable to me.)
Am I missing something? This a bug? Some other way to skin this cat?