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: 
Try this

```swift
@State private var viewSize: CGSize = .zero

var body: some View {
    VStack {
        // ...
    }
    .background(GeometryReader { proxy in
        Color.clear.preference(
            key: ViewSizePreferenceKey.self,
            value: proxy.size
        )
    })
    .onPreferenceChange(ViewSizePreferenceKey.self) { size in
        viewSize = size
    }
}

private struct ViewSizePreferenceKey: PreferenceKey {
    static var defaultValue: CGSize = .zero
    static func reduce(value: inout CGSize, nextValue: () -> CGSize) {
        value = value.width + value.height > nextValue().width + nextValue().height ? value : nextValue()
    }
}

```
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
        }      
    }
}

```