Created
April 26, 2023 13:15
-
-
Save ingconti/e0a2ceaf243ff2e27ed02144e506d996 to your computer and use it in GitHub Desktop.
Cannot assign to property: 'self' is immutable FIX it!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AllowChangeContentView.swift | |
// simpleSample | |
// | |
// Created by ing.conti on 26/04/23. | |
// | |
/* You got: Cannot assign to property: 'self' is immutable | |
if You write; | |
struct ContentView: View { | |
var msg = "" | |
... | |
write SO: | |
@State var msg = "" // CORRECT! | |
*/ | |
import SwiftUI | |
struct ContentView: View { | |
//var msg = "" // WRONG! try to uncomment.. | |
@State var msg = "" // CORRECT! | |
var body: some View { | |
VStack { | |
Text(msg) | |
Button("Fill me!", action: { | |
fillMe() | |
}) | |
} | |
.padding() | |
} | |
func fillMe(){ | |
self.msg = "Hello!!" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment