0

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?

FunBear
  • 11
  • 1
  • 1
    Is `models` an array of `String`? Please post some more code, we can't [reproduce your example](https://stackoverflow.com/help/minimal-reproducible-example). – HunterLion Oct 29 '22 at 04:50
  • I have amended my question. I'm playing around with this for now, so I don't have a lot of code to begin with as it's taken from the response I linked to. – FunBear Oct 29 '22 at 17:00

0 Answers0