How to conform an Array to 'Identifiable'

270 views Asked by At

I'm confused about how Identifiable arrays work. For instance, I have the following array returned as a response to a function:

Optional (["Jane", "John", "Eric", "Erika", "Motto"])

Now, I want to show this as a list but we know that list items need to conform to Identifiable. How can I conform an array like this to 'Identifiable'? I was looking at this question but it didn't seem to help a lot.

1

There are 1 answers

2
Mansidak On

I figured it. simple doing the following should do the job:

    @State private var options: [String] = []
    // then use this

          ForEach(options, id:\.self){ option in
            Text(option)