I have
struct ContentView: View {
@State var n: Int
init() {
_n = 3
}
On the line with _n = 3
, i get the error Cannot assign value of type 'Int' to type 'State<Int>'
How do I fix this?
The error is fairly self-explanatory. _n
is of type State<Int>
and you're trying to assign an integer to it.
You can create a State<Int>
instance like so
_n = State(initialValue: 3)
but it's not clear why you're doing it. You should just assign the initial value directly:
@State var n: Int = 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With