nalexn / clean-architecture-swiftui

SwiftUI sample app using Clean Architecture. Examples of working with CoreData persistence, networking, dependency injection, unit testing, and more.
MIT License
5.57k stars 671 forks source link

Question: External events #23

Closed avishnyak closed 3 years ago

avishnyak commented 4 years ago

How would you add a BLE peripheral manager to this architecture?

Seems like it would be a handler but where would the business logic of responding the events go?

nalexn commented 4 years ago

Any service that does not rely on any delegate methods in AppDelegate can be represented as an isolated entity and put inside DIContainer.

If the entity accepts any input from the UI, you'd need to add an Interactor, otherwise, you can go with a "handler" with a private access level for the UI.

In the case with BLE manager, it looks like you'd need to accept some input from the user, likewise which device to connect to / whether to start or stop BLE advertising. This means you need to have an Interactor. Depending on how much business logic you have it might be worthwhile splitting the Interactor into two entities, one that is responsible for UI handling business logic, and another taking care of the connectivity and other low-level details. Just make sure to expose a minimal and clear API to the UI layer, it should not be aware of any implementation details and technology domain.