Difference between value type and a reference type in iOS swift?

This is one of the basics of every programming language. Most of us might have started programming with C language. If you still remember the function call by value and call by reference, you might get some idea about what this exactly is. let’s see what apple says about this.

Abhimuralidharan
iOS Essentials

--

As the title says, there are two categories a type in swift can fall into:

  • Value Type
  • Reference Type

Very basic definition:

Value Type — each instance keeps a unique copy of its data. A type that creates a new instance (copy) when assigned to a variable or constant, or when passed to a function.

Reference Type — each instances share a single copy of the data. A type that once initialized, when assigned to a variable or constant, or when passed to a function, returns a reference to the same existing instance.

Have a look at the following gif to get a proper understanding about what you just read.

--

--