Question: How is it possible to set a @State var inside a geometryReader?

This is my code:

```swift
@State var isTest:Int = 0

var body: some View {
    VStack{
        ForEach(self.test, id: \.id) { Test in
            VStack{
                GeometryReader { geometry in
                    self.isTest = 1

```

I try with a function but it doesn't work.

```
@State var isTest: Int = 0

func testValue() {
    self.isTest = 1
}

var body: some View {
    VStack{
        ForEach(self.test, id: \.id) { Test in
            VStack{
                GeometryReader { geometry in
                    testValue()

```

Any idea? Thanks!

Answer: 
I also had a similar problem yesterday. But I was trying to pass a value from inside the GeometryReader.

I tried a couple of ways but it didn't work.
When I use `@State var` to declare the variable, the compiler again complained in a purple line saying that Modifying the view during update will make it become Undefined.

When I tried to declare a variable using `var` only, the compiler just told me that it's immutable.

And then, I tried storing it onto my `@EnvironmentObject`. And I just got a dead loop.

So, my last hope was using the notification way and some how it worked. But I don't know if it's the standard way of implementation.

```
@State private var viewPositionY:CGFloat = 0

```

First, post the value `frame.origin.y` via notification.

```
 GeometryReader{ geometry -> Text in
        let frame = geometry.frame(in: CoordinateSpace.global)
        NotificationCenter.default.post(name: Notification.Name("channelBlahblahblah"), object:nil, userInfo:["dict":frame.origin.y])
        return Text("My View Title")
 }

```

And then declare a publisher to receive the notification.

```
private let myPublisher = NotificationCenter.default.publisher(for: Notification.Name("channelBlahblahblah"))

```

Finally, use the the .onReceive modifier to receive the notification.

```
.onReceive(myPublisher) { (output) in

   viewPositionY = output.userInfo!["dict"] as! CGFloat
   //you can do you business here
}

```
You can update `@State` variables in the `onAppear` method if you need the initial geometry values

```
@State var windowSize = CGSize()

var body: some View {

    return GeometryReader { geometry in 
        VStack {
            Text("Hello SwiftUI")  
        }
        .onAppear {
            windowSize = geometry.size
        }      
    }
}

```