Immutability

Before we discuss immutability, let's start by answering a question:

What datatype is more secure to work with in a multithreaded environment?

  • Variable datatype, which can be changed over time, or
  • Constant datatype, which cannot be changed once populated

Let me try to explain the question with the help of an example—suppose you had a variable dictionary of position coordinates:

var locationDictionary = ["latitude": 131.93839, "longitude": 32.83838]

locationDictionary is the location of the user that gets populated once every five minutes; this locationDictionary will, at some time in the near future, be converted to a locations JSON object and synced to the backend (an API pushing data to the server) from where the location ...

Get Reactive Programming with Swift 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.