# Mutating an Optional-wrapped value type

**URL:** <https://forums.swift.org/t/mutating-an-optional-wrapped-value-type/84582>\
**Category:** Using Swift\
**Tags:** optional\
**Created:** [February 5, 2026, 4:18pm UTC](https://forums.swift.org/t/mutating-an-optional-wrapped-value-type/84582 "2026-02-05T16:18:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [February 5, 2026, 4:18pm UTC](https://forums.swift.org/t/mutating-an-optional-wrapped-value-type/84582/1 "2026-02-05T16:18:46Z")

</div>

If I want to mutate a value that’s within an Optional, I’d have to use an `if`-`var` or similar, mutate that copy, then copy it back? I did find out that mutating instance methods can work through a `myVariable?.selfMutatingMethod`.

---

<div class="post-metadata">

**Author:** ![ole](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ole/32/18720_2.png) [@ole](https://forums.swift.org/u/ole)\
**Post date:** [February 5, 2026, 4:33pm UTC](https://forums.swift.org/t/mutating-an-optional-wrapped-value-type/84582/2 "2026-02-05T16:33:03Z")

</div>

I'm not sure what exactly you want to do. For what it's worth, you can use `someOptional?` as an L-value and mutate that, like this:

```swift
var x: Int? = 1
x? += 100 // Note the question mark
print(x) // Optional(101)

```

The behavior is equivalent to a `mutating` method such as `x?.add(100)`. If `x` had been `.none`, line 2 would have had no effect, and `x` would still be `.none` in line 3.

---

<div class="post-metadata">

**Author:** ![JacobHearst](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jacobhearst/32/31923_2.png) [@JacobHearst](https://forums.swift.org/u/JacobHearst)\
**Post date:** [February 10, 2026, 1:59pm UTC](https://forums.swift.org/t/mutating-an-optional-wrapped-value-type/84582/3 "2026-02-10T13:59:39Z")

</div>

Optional also has the `map` and `flatMap` operators that you can use to unwrap, mutate, and return an optional value.

To follow with @ole ‘s example:

```swift
var x: Int? = 1
x = x.map { unwrapped in
    unwrapped + 100
}
// Or, more concisely:
// x = x.map { $0 + 100 }

print(100) // Optional(101)

```

---

<div class="post-metadata">

**Author:** ![rayx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rayx/32/12204_2.png) [@rayx](https://forums.swift.org/u/rayx)\
**Post date:** [February 10, 2026, 3:12pm UTC](https://forums.swift.org/t/mutating-an-optional-wrapped-value-type/84582/4 "2026-02-10T15:12:49Z")

</div>

Optional chaining is better in this case because it's in-place modification and works with noncopyable optional.
