-
Notifications
You must be signed in to change notification settings - Fork 9
Interactor
Ryan Bush edited this page Apr 21, 2017
·
5 revisions
An Interactor
is responsible for data logic. It is the layer that retrieves the data from any source it needs to. For instance, it can communicate with a Service or a local data store such as CoreData.
It has outlets only to the Presenter of the VIPER stack, something like this:
weak var presenter: InteractorToPresenterInterface!
Lets take a look at a typical flow. Lets say your user wants to login to the application, so the presenter has been told the user wants to login with their username and password:
//Presenter.swift
func userTappedLogin(withUsername username: String, andPassword password: String) {
interactor.login(withUsername: username, andPassword: password)
}
//Interactor.swift
lazy var loginService: LoginService = LoginService()
func login(withUserName username: String, andPassword password: String) {
loginService.login(withUsername: username, andPassword: password,
success: { (user: User) in
self.loggedIn(withUser: user)
},
failure: { (error: Error) in
self.failedLogin(withError: error)
})
}
Here, the Interactor
is told to login with the username and password by the Presenter.