In VIPER, unlike the MVC, the role and place not so clearly defined for NSFetchedResultsController.
Is it right to place it on the interactor?
So, What is VIPER architecture? VIPER is a backronym for View, Interactor, Presenter, Entity, and Router. This architecture is based on Single Responsibility Principle which leads to a clean architecture. View: The responsibility of the view is to send the user actions to the presenter and shows whatever the presenter tells it.
So VIPER is developed to increase the method to test the software in a better way in the application architecture. VIPER provides the defined architecture to iOS applications in all the mobile and software components. The VIPER is expanded as View, Interactor, Presenter, Entity, and Routing.
All the VIPER modules are sitting inside the Modules folder. Everything that's network or data related goes to the Services folder (api service, core data service, location service, etc.) and later on gets used in the module builder depending the current environment (for example mock implementation for testing).
In this tutorial, you’ll learn about using the VIPER architecture pattern with SwiftUI and Combine, while building an iOS app that lets users create road trips. The VIPER architectural pattern is an alternative to MVC or MVVM.
According to this article interactor should not know how to persist the entities.
VIPER and the architecture that uses NSFetchResultController are different approaches. There is no right place for NSFetchResultController in VIPER.
VIPER is good for big application as it provides architecture layers that are isolated well.
NSFetchResultController is good for smaller application as it helps to develop faster.
NSFetchedResultsController is a Core Data specific way for observing database changes. It's a popular pattern to use and can be found in most mobile database systems.
It's possible to use this kind of observation underneath a database abstraction layer, so if we take a full VIPER architecture of a mobile application it can be implemented underneath the Interactor. According to the accepted answer it shouldn't be put into the Interactor, because the Interactor shouldn't know about the type of local database it's using. Though I can't come up with anything against using it at a database level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With