Overview - Reference sharing and side effects
What is it?
Reference sharing happens when two or more variables point to the same object in memory. This means changes made through one variable affect the others because they share the same data. Side effects occur when a change in one place unexpectedly changes data elsewhere, often due to reference sharing.
Why it matters
Without understanding reference sharing, you might accidentally change data in one part of your program and cause bugs in another. This can make your app behave unpredictably and be hard to fix. Knowing how references work helps you write safer, clearer code that avoids hidden surprises.
Where it fits
Before this, you should know about variables, constants, and basic data types in Swift. After this, you can learn about value types versus reference types, memory management, and how to use Swift’s copy-on-write behavior to control side effects.