4

I searched a lot, I understand that the view controller is actually the "View" in the Viper or MVP architecture and the Presenter contains the logic... But since the presenter should be easy testable, is it good to put Core Location stuff (like LocationManager and location updates) into the presenter? Or should I put in view controller and notify the presenter?

4

1 回答 1

5

I'd solve this by creating a LocationService object which wraps all of the Core Location methods, and exposes their output, maybe exposing the results of location updates as a stream (if you're using Rx) or else a callback.

I'd use Dependency Injection (perhaps using Swinject) to inject this into the presenter layer in MVP, or the interactor layer in VIPER (because the location information presumably affects the core business logic of the app). In order to test the app, create a 'mock' version of this service serving test data and inject it into the presenter/interactor in your tests.

于 2018-01-18T11:54:22.560 回答