I am reading this post on async ModelEntity
loading, and the code is clear. What I fail to understand is how I can substitute the model call for Entity.loadModelAsync(named: "Glasses.usdz")
with my chosen model through a [String]
or String
, such as when making a new function with the model name in the parameters, like
Entity.loadModelAsync(named: models.randomElement())
This results in the warning Cast from 'String' to unrelated type 'ModelEntity' always fails
I was expecting a simple substitution for what looks like a String
to not be a problem, but I am being confronted with errors about "unrelated data types" when my personal logic says that something "in quotes" should be possibly called through a String
, e.g. data I am storing inside a [String]
.
My models
array is an array of String
names of models I have loaded inside my app bundle. I would like to use any model's name as the input string in the call to Entity.loadModelAsync(named:)
through the .randomElement()
function of the array.
let models = ["Robot.usdz", "Airplane.usdz", "Beachball.usdz"]
or
let models = ["customModel1", "customModel2", "customModel3"]
Why is Swift so finicky about an object's name property?