'How to organize data shared between several viewControllers?

Currently the app I am working on uses Bluetooth LE to communicate with a microcontroller which has a sensor on it and collects data by measurements.

Microcontroller has a set of parameters which are all configurable. Those measurement settings are configured by sending AT commands via Bluetooth and that can be done from different screens in the app.

When a measurement is finished, I need to store all the collected data somewhere as well as settings under which that measurement was executed. Different screens need to display this data and I am wondering what the best way to this is. I was thinking about having Measurement as a singleton and all of the screens would then read properties of an object of Measurement class and then display that data, but I do not like that approach.

I am wondering how to keep my code as clean as possible, separating responsibilites among different classes (for example BluetoothManager does not need to know about anything specific about the measurement or configuration of microcontroller themselves).

Generally, I would like to get some good advice on clean code in Swift, maybe some resources or tutorials which handle this in a project. An example project with a similar theme such as this one (CoreBluetooth, handling data that is needed across the app) would be great.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source