So, I am new to VIPER and have built simple demo app of http request using the architecture. I got an issue where the UI are not updated although the the method within the view is still called because I have checked that the print("test") is executed and shown on the debug console. This is the relevant code:
View :
private func getAllContacts(){
self.contacts = []
self.hud.show(in: self.view)
self.presenter?.fetchListContacts()
print("asd")
}
Presenter :
func fetchListContacts(){
print("sdf")
interactor?.getContacts()
}
Interactor :
func getContacts(){
print("123")
var contacts : [DetailContact] = []
contacts = \\APICALL
self.presenter?.listContactFetchSuccess(contacts)
}
Baxk to PResenter :
func listContactFetchSuccess(_ contacts: [DetailContact]) {
print("gxx")
view?.fetchSucceed(contacts: contacts)
}
back to View :
func fetchSucceed(contacts: [DetailContact]) {
self.contacts = contacts
self.hud.dismiss()
self.contactTableView.reloadData()
print("test")
}
My Router :
static func createListContactModule() -> ListViewController {
let view = mainstoryboard.instantiateViewController(withIdentifier: "ListViewController") as! ListViewController
var presenter: ViewToPresenterListProtocol & InteractorToPresenterListProtocol = ListContactPresenter()
var interactor: PresenterToInteractorListProtocol = ListContactInteractor()
let router:PresenterToRouterListProtocol = ListContactRouter()
view.presenter = presenter
presenter.view = view
presenter.router = router
presenter.interactor = interactor
interactor.presenter = presenter
return view
}
The progress hud at least closes? or does not suffer any change?
I suggest you put the content of your function
fetchSucceed(contacts: [DetailContact])
into the main queue like:Maybe the API call that you use, is changing the thread of the excecution therefore your UI calls are not showing, because it always must be excecuted in the main thread.