Junior — Middle
How is the information obtained from an interactor passed to the presenter?
sobes.tech AI
Answer from AI
In the VIPER architecture, the interactor is responsible for business logic and data retrieval, while the presenter prepares data for display in the view.
Information from the interactor is usually passed to the presenter through a protocol (interface) that the presenter implements. The interactor calls methods of this protocol, passing the received data or operation results. Thus, the presenter receives the data and updates the interface state.
Example:
protocol InteractorOutput: AnyObject {
func didFetchData(_ data: [String])
}
class Interactor {
weak var output: InteractorOutput?
func fetchData() {
// Get data
let data = ["item1", "item2"]
output?.didFetchData(data)
}
}
class Presenter: InteractorOutput {
func didFetchData(_ data: [String]) {
// Process data and update View
print("Data received: \(data)")
}
}
Thus, the interactor passes data to the presenter via a delegate (output).