I can’t see the images leaving some even if I name them the same even if I run it or use simulator it’s the same.

iam seeing some of the images but not in every row or column any answers. And any ideas on how to print text below every image like a description, I tried in one of them writing denim but it didn't work. Like this:-

Answered by robnotyou in 702251022

In a SwiftUI ForEach, each item must be uniquely Identifiable.
In your ForEach, you use the "id" parameter, to specify how to uniquely identify each item...

ForEach(clothimages, id: \.self)

If your items are not unique (they are not!), then they will not display correctly.
This is how ForEach works.

In your clothimages, it is the image name that must be unique, for the ForEach to work.
Update clothimages, so that all image names are unique.


To print text below your images, try:

func maincustom(content: Image, text: String) -> some View {
    VStack {
        content
            .resizable()
            .frame(width: 200, height: 250)
        Text(text)
    }
    .padding(8)
}
Accepted Answer

In a SwiftUI ForEach, each item must be uniquely Identifiable.
In your ForEach, you use the "id" parameter, to specify how to uniquely identify each item...

ForEach(clothimages, id: \.self)

If your items are not unique (they are not!), then they will not display correctly.
This is how ForEach works.

In your clothimages, it is the image name that must be unique, for the ForEach to work.
Update clothimages, so that all image names are unique.


To print text below your images, try:

func maincustom(content: Image, text: String) -> some View {
    VStack {
        content
            .resizable()
            .frame(width: 200, height: 250)
        Text(text)
    }
    .padding(8)
}

For your next question, please try pasting your code into a code block (using "Paste and Match Style"), instead of using screenshots.

So it means if I am trying to print same images I need to remove id else use different images, am I right?

Not sure to understand.

What do you mean by "print same image" ?

To change what is on screen, you have to update the dataSource, clothimages

What I understood is that I need to use id for unique images and not to use id for the same images in the array. Is it? Correct me if Iam wrong.

No, you can have the same image content, they are different objects in the array. So you can use id. And image will appear several times.

👍

I can’t see the images leaving some even if I name them the same even if I run it or use simulator it’s the same.
 
 
Q