Skip to content

Architecture

Artem Kalmykov edited this page Aug 27, 2020 · 5 revisions

Architecture

Clean Swift

Clean Swift is used as a main architecture of the project. It's a bit modified version of the normal Clean Swift. Also it is extended with services to better manage networking, data persistence and sensors communication.

See these templates, which are used for development: clean_swift_templates.zip

Local storage

Local storage is implemented with the use of Realm. The Realm methods are not exposed outside of Realm model classes. All Realm.write calls are done inside model classes. Using UserDefaults is avoided.

Network communication

Currently the application uses network only for Nightscout sync. Because of this all networking logic is present only in NightscoutService and corresponding classes. No third-party libraries are used, all the requests are done via native URLSession.

Error handling

The project utilised Swift's error handling approach using Error, LocalizedError, throw and do-catch. So if you need to trigger an error, create a custom error enum and adopt Swift's LocalizedError protocol. Then declare your function as throws and throw your error from your function. Catch it in do-catch structure and handle appropriately.

UI

The project doesn't contain any storyboards. Each UIViewController may have a corresponding .xib file if required. All supplementary views may also have appropriate .xib files. If any view which has a xib has to be embedded into another xib, it should be subclassed from NibView. See its implementation for more details.