Reputation: 146
I was trying to implement viper architecture on my Xcode. I am following an article https://medium.com/cr8resume/viper-architecture-for-ios-project-with-simple-demo-example-7a07321dbd29.
also, I downloaded the article source code, and run well also UI is changing. but when I created a new project with swift 5 and copy all methods and classes. after running UI is not updating but both codes are the same. please check below
This is a single-page sample code
please check this Github for my project https://github.com/Faizulkarim/movieHut/tree/main/MovieHutWithViper
This is my protocol
protocol PresenterToViewProtocol: AnyObject{
func showMovieList(MovieList: Array<movieModel>)
}
Here o call showMovieListMethod
extension MoviePresenter : InteractorToPresenterProtocol {
func movieFetchSuccess(movieModelArray: Array<movieModel>) {
view?.showMovieList(MovieList: movieModelArray)
}
}
// on MovieListViewController confirmed delegate
extension MovieListViewController:PresenterToViewProtocol{
func showMovieList(MovieList: Array<movieModel>) {
self.Movies = MovieList
self.cover.backgroundColor = UIColor.red
print(self.movies.count)
self.trandingTableView.reloadData()
}
}
on showMovieList function call, it's printing the total count of movies. But when I reloadtableview() table view is not interacting is showing any data. Even when I set to change the background of a view it's not changing. when I set breakpoint is' stop. So protocol is called properly but UI is not updating. i search in google didn't find relevant answer.
Upvotes: 1
Views: 212
Reputation: 9
You might be in a background thread. You can only update UI from main thread.
Try to update like this:
DispatchQueue.main.async {
self.trandingTableView.reloadData()
}
Upvotes: 0