SwiftUI requires items in a List to be uniquely identifiable so what is happening is that you are getting repeating elements from the arrayOf5 appearing in the List and that’s what the warning message is referring to.
For the time being just ignore the message in the console. In time you will learn about how to make items in a List uniquely identifiable and then it will all make sense.
Not sure how far you got, but I just did the challenge & was able to create unique ids for each element I was adding to the list by rewriting the items id with a new UUID every time I pulled a word.
import SwiftUI
struct WordView: View {
var wordItems:[WordItem] = [WordItem(word: "Blue"),
WordItem(word:"Red"),
WordItem(word:"Yellow"),
WordItem(word:"Orange"),
WordItem(word:"Green")]
@State var wordList:[WordItem] = []
var body: some View {
VStack {
List(wordList) { wrd in
Text(wrd.word)
}
Button("Add Random Word") {
addWord()
}
.listStyle(.plain)
}
}
func addWord(){
//stores random word item from list of available word items
var wValue = wordItems[Int.random(in: 0...4)]
//assigns unique value to word item
wValue.id = UUID()
//adds new word to list
wordList.append(wValue)
}
}
#Preview {
WordView()
}
Whilst that solves the uniquely identifiable array element issue, you are applying advanced knowledge which is covered later in the courses by placing data in a struct with an id. I would imagine that your struct would have been something like:
struct WordItem: Identifiable {
var id = UUID()
var word: String
}
Well done. There’s nothing wrong with trying to be a little bit ahead of the game. If you’ve already got a bit of programming experience, things do tend to fall into place a bit easier.