Last active
April 7, 2017 14:49
-
-
Save gracietti/27986bc339cb05134381815d545603ec to your computer and use it in GitHub Desktop.
Example of Interactor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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