I'm trying to create a messenger app and this error shows up. Can someone help me?
Referencing initializer 'init(_:content:)' on 'ForEach' requires that 'Message' conform to 'Identifiable'
You should add .self
ForEach(chatManager.messages, , id: \.self) { message in
If your Message
type has an id
property, you just need to add the protocol conformance for Identifiable
.
struct Message: Identifiable /* Other protocols here */ {
var id = UUID()
/*
Rest of implementation here...
*/
}
Get full answer in the othre thread.
For this, simply change as:
struct Message : Hashable { // <<-- CHANGE HERE
let text: String
let sender: String
}
And don't forget to close the thread by marking the correct answer.