Junior — Middle
How does changing an input parameter inside a function affect memory space when the values are not changed?
sobes.tech AI
Answer from AI
In iOS (and in Swift in particular), when passing parameters to a function, values are copied if it is a value type, such as structures or basic types. If you do not modify the parameter inside the function, the memory area where the original value is stored does not change — a copy of the parameter exists separately.
For reference types, such as classes, a reference to the object is copied, not the object itself. Modifying the parameter inside the function, if it does not affect the properties of the object, will not change the original object.
Thus, if values are not changed, the memory area of the original data remains unchanged, and the function works with a copy or a reference without modification.