# \#assignment

**URL:** https://forums.swift.org/tag/assignment/325.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Assign if different](https://forums.swift.org/t/assign-if-different/61168)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 15\
**Last updated:** [November 10, 2022, 3:14pm UTC](https://forums.swift.org/t/assign-if-different/61168 "2022-11-10T15:14:04Z")

</div>

We don't have "assign if different" in Swift other than writing it explicitly: if a != b { a = b } Which is not ideal and getting worse in case of complex expressions: let b = expression(x, y, z) if foo\[123\].bar\[b…

---

## [Custom Operator Assignment in Initialization](https://forums.swift.org/t/custom-operator-assignment-in-initialization/44592)

<div class="topic-metadata">

**Author:** [@Freytag](https://forums.swift.org/u/Freytag)\
**Replies:** 5\
**Last updated:** [February 11, 2021, 10:17am UTC](https://forums.swift.org/t/custom-operator-assignment-in-initialization/44592 "2021-02-11T10:17:33Z")

</div>

Hey, everyone. I have a wrapper type Observable\<Value\> wherein the wrapped value is kept in a base property, very similar to the AnyHashable wrapper type. A custom set of operators beginning with "^^" are defined as well…

---

## [Syntactic sugar for assigning Optional values and conditional assignment](https://forums.swift.org/t/syntactic-sugar-for-assigning-optional-values-and-conditional-assignment/40018)

<div class="topic-metadata">

**Author:** [@Vsevolod](https://forums.swift.org/u/Vsevolod)\
**Replies:** 9\
**Last updated:** [September 4, 2020, 4:06pm UTC](https://forums.swift.org/t/syntactic-sugar-for-assigning-optional-values-and-conditional-assignment/40018 "2020-09-04T16:06:06Z")

</div>

Hi Team! I hope you are doing well. I'm sorry for such a minor ideas but for my project they will make code more compact. Assigning optional only if it has a value. E.g.: var a: Int? var b = 0 instead of: if (a !…

---

## [Resource access and lifecycle](https://forums.swift.org/t/resource-access-and-lifecycle/33118)

<div class="topic-metadata">

**Author:** [@joehodge3rd](https://forums.swift.org/u/joehodge3rd)\
**Replies:** 1\
**Last updated:** [January 27, 2020, 7:45pm UTC](https://forums.swift.org/t/resource-access-and-lifecycle/33118 "2020-01-27T19:45:29Z")

</div>

As Swift continues to evolve, it has become difficult to prevent multiple accessors from modifying all resources in a coordinated manner such that copies of accessors to memory (variable value assignment) in multiple con…
