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: 
While putting code into function is a nice touch, there may arrive another problem and that is altering the @State variable during update phase:
`[SwiftUI] Modifying state during view update, this will cause undefined behavior`

Using NotificationCenter to move @State variable update *after* view update phase can help, but one could use much more simple solution like performing variable update right after render phase by using `DispatchQueue`.

```
@State var windowSize = CGSize()

func useProxy(_ geometry: GeometryProxy) -> some View {

    DispatchQueue.main.async {
        self.windowSize = geometry.size
    }

    return EmptyView()
}

var body: some View {

    return GeometryReader { geometry in
        self.useProxy(geometry)    

        Text("Hello SwiftUI")        
    }
}

```
You can use [onAppear(perform:)](https://developer.apple.com/documentation/SwiftUI/AnyView/onAppear(perform:)) to update `@State` variables with the initial view size and [onChange(of:perform:)](https://developer.apple.com/documentation/swiftui/form/onChange(of:perform:)) to update the variables when the view size changes:

```
struct MyView: View {
  @State private var size: CGSize = .zero

  var body: some View {
    GeometryReader { geometry in
      ZStack {
        Text("Hello World")
      }.onAppear {
        size = geometry.size
      }.onChange(of: geometry.size) { newSize in
        size = newSize
      }
    }
  }
}

```