Learn Courses My Dashboard

AR ForEach Help Please

Hi there,

I am trying to create an AR model viewer based on the ARCourse here on CWC. This has some models which are defined in a JSON. I’ve created a model and DataService to decode but can’t get the ForEach to work in ContentView. Please could you help?

What does your modelTitle look like?

Your id is an int change it to a string so it can iterate it…and it can display on your text field

Var Id:string

Var Id = uuid()

ForEach(model, Id:.id) { i in


Or with int try this

ForEach(model, Id:.Id) {


Hi Jermaine,

I really appreciate your help. Thanks.

The modelTitle is a string as in the image of the json attached.

I’ve tried the changes to the ForEach loop but still get some errors. The Id is on line 7. Please could you advise?

Again, many thanks for your help.

you getting it wrong you need to decode your json in to your model and use combine framework to pass watch the recipe tutorials you will get it on cwc+


Hi Adrian,

In your Models.swft file do you have a Published property which is an array for each one of your JSON elements to be stored in after decoding and do you have an init() { } function that is calling your DataService to decode your JSON into that array?


The other thing that will help us to help you is if you post your code as text rather than a screenshot.

To format the code nicely, place 3 back-ticks ``` on the line above your code and 3 back-ticks ``` on the line below your code. Like this:

Code goes here

The 3 back-ticks must be the ONLY characters on the line. The back-tick character is located on the same keyboard key as the tilde character ~ (which is located below the Esc key - QWERTY keyboard).

Alternatively after you paste in your code, select that code block and click the </> button on the toolbar. This does the same thing as manually typing the 3 back ticks on the line above and below your code.

This also makes it easier for anyone assisting as they can copy the code and carry out some testing.

Can you post your JSON code in a reply.