# Does a subscript setter return a reference to struct?

**URL:** <https://forums.swift.org/t/does-a-subscript-setter-return-a-reference-to-struct/75289>\
**Category:** Using Swift\
**Created:** [October 10, 2024, 7:58pm UTC](https://forums.swift.org/t/does-a-subscript-setter-return-a-reference-to-struct/75289 "2024-10-10T19:58:09Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![vanvoorden](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vanvoorden/32/33619_2.png) [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Post date:** [October 10, 2024, 8:09pm UTC](https://forums.swift.org/t/does-a-subscript-setter-return-a-reference-to-struct/75289/3 "2024-10-10T20:09:38Z")

</div>

> [@giik](#):
>
> Did we somehow get a reference to a non-reference type `S`?

[![](https://global.discourse-cdn.com/swift/original/3X/0/d/0ded84e2fc9a726dda6e0e0c677968e570969694.jpeg "Ben Cohen - Fast Safe Mutable State") ](https://www.youtube.com/watch?v=BXJIIQ-B4-E)

The Swift standard library copy-on-write collections are built on `read` and `modify` as an optimization to defend against "accidental quadratics". See this @ben-cohen lecture for more background on that.

---

_[View the full topic](https://forums.swift.org/t/does-a-subscript-setter-return-a-reference-to-struct/75289)._
