O'Reilly logo

Swift 3 Functional Programming by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The benefits of immutability

We already know that immutability helps safety and performance, but in real-world application development, immutability can provide us with more benefits, which will be explained in the following sections.

Thread safety

Immutable objects are useful in multithreaded applications because multiple threads can act on the data of immutable objects without worrying about changes to the data by other threads.

As immutable objects are closed to change, it is safe to assume that they will stay unchanged while we access the object from different threads. This assumption simplifies most of the multithreading problems that are complex to solve and maintain. For instance, we do not need to think about the synchronization/locking mechanism ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required