Nawaf
Nawaf

Reputation: 396

Swiftui Cannot assign to property: 'self' is immutable Error

I'm facing an error says "cannot assign to property" as seen in the preview image.

I get this error when I use the variable inside the struct of View and inside the forEach.

Here's Screenshot.enter image description here

Upvotes: 9

Views: 12513

Answers (1)

Rob Napier
Rob Napier

Reputation: 299683

Define your currentMood as a @State variable:

@State var currentMood: String

You'll likely need to assign it with self.currentMood = moodData (adding self.)

Upvotes: 24

Related Questions