Skip to content

Instantly share code, notes, and snippets.

@gracietti
Last active April 7, 2017 14:49
Show Gist options
  • Save gracietti/27986bc339cb05134381815d545603ec to your computer and use it in GitHub Desktop.
Save gracietti/27986bc339cb05134381815d545603ec to your computer and use it in GitHub Desktop.
Example of Interactor
class MainSearchInteractor {
// Properties
weak var output: MainSearchInteractorOutput?
var apiDataManager = ProfileApiDataManager()
var localDataManager = ProfileLocalDataManager()
}
extension MainSearchInteractor: MainSearchUseCase {
func searchProducts(with searchTerm: String, onPage page: Int) {
// Code below show how interactor get data from API and then saves it on local DB with separate data managers
self.apiDataManager.searchProducts(with: searchTerm, forPage: page) { (products) in
if let products = products {
self.localDataManager.updateSearchResultFavorites(products) { (products) in
self.output?.onFetchProductsSuccess(Array(products), shouldAppend: page != 1)
}
} else {
self.output?.onFetchProductsSuccess(nil, shouldAppend: page != 1)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment