# @State of optional: type spelling Optional\<Int\> is not the same as Int?

**URL:** <https://forums.swift.org/t/state-of-optional-type-spelling-optional-int-is-not-the-same-as-int/62780>\
**Category:** Using Swift\
**Created:** [January 25, 2023, 3:36am UTC](https://forums.swift.org/t/state-of-optional-type-spelling-optional-int-is-not-the-same-as-int/62780 "2023-01-25T03:36:47Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![young](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/young/32/7878_2.png) [@young](https://forums.swift.org/u/young)\
**Post date:** [January 25, 2023, 6:31pm UTC](https://forums.swift.org/t/state-of-optional-type-spelling-optional-int-is-not-the-same-as-int/62780/6 "2023-01-25T18:31:02Z")

</div>

Oh wow! Double assignments and a third different outcome with the same code of optional variables . So you have both `a` and `b` using both optional spellings.

If you comment out `b`, now `a` is nil instead of getting value assigned in init!

```swift
struct FooFooFoo: View {
    @State var a: Int?
    @State var b: Optional<Int> // 1. try comment this out
    
    
    init() {
        a = 1234
        b = 4444 // 2. comment this out
    }
    
    var body: some View {
        VStack {
            Text("a = \(a ?? -1)")
            Text("b = \(b ?? -1)") // 3. comment this out
        }
    }
}

```

So the exact same code behave differently depend on whether you have another optional variable is present or not!

Edit: see the conclusion to as why this is so: [SwiftUI @State PW exact same code different result if another optional is added!? :=( - #9 by young](https://forums.swift.org/t/swiftui-state-pw-exact-same-code-different-result-if-another-optional-is-added/62789/9)

---

_[View the full topic](https://forums.swift.org/t/state-of-optional-type-spelling-optional-int-is-not-the-same-as-int/62780)._
