# @State messing with initializer flow

**URL:** <https://forums.swift.org/t/state-messing-with-initializer-flow/25276>\
**Category:** Using Swift\
**Tags:** off-topic\
**Created:** [June 5, 2019, 2:55pm UTC](https://forums.swift.org/t/state-messing-with-initializer-flow/25276 "2019-06-05T14:55:28Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![Lantua](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lantua/32/8868_2.png) [@Lantua](https://forums.swift.org/u/Lantua)\
**Post date:** [April 22, 2020, 7:29pm UTC](https://forums.swift.org/t/state-messing-with-initializer-flow/25276/18 "2020-04-22T19:29:47Z")

</div>

> [@ever](#):
>
> another where you want to initialize with default data values

You mean to have values in both views decoupled until you press `save` or something? I've been using a combination of `State`, `Binding` and `onAppear`:

```swift
struct Form: View {
  @Binding var value: ...
  @State var state: ...
  var body: some View {
    ...
      .onAppear { self.state = self.value }
  }
}

```

but of course you need custom logic to save, by writing back to `value`. Note that `onAppear` is a method of `View`, so any view will do.

PS

> [@Assignment to @State var in init() doesn't do anything, but the compiler gen'ed one works](https://forums.swift.org/t/assignment-to-state-var-in-init-doesnt-do-anything-but-the-compiler-gened-one-works/35235/1):
>
> Please read @DevAndArtist's and @Lantua's comment in this thread for authoritative explanations.

Lol, I'm far from authoritative. Just an experimentation lunatic.

---

_[View the full topic](https://forums.swift.org/t/state-messing-with-initializer-flow/25276)._
