You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import Foundation
classObservable<T>{
// 3) 호출되면, 2번에서 받은 값을 전달한다.
privatevarlistener:((T)->Void)?
// 2) 값이 set되면, listener에 해당 값을 전달한다,
varvalue:T{
didSet {listener?(value)}}
// 1) 초기화함수를 통해서 값을 입력받고, 그 값을 "value"에 저장한다.
init(_ value:T){self.value = value
}
// 4) 다른 곳에서 bind라는 메소드를 호출하게 되면,
// value에 저장했떤 값을 전달해주고,
// 전달받은 "closure" 표현식을 listener에 할당한다.
func bind(_ closure:@escaping(T)->Void){closure(value)
listener = closure
}}
import Foundation
classSearchViewModel{letsearchView=SearchView()vardownloadedMovies:Observable<Movie>=Observable(Movie(movie:[]))varmovieQuery:Observable<String>=Observable("")vartitle:Observable<String>=Observable("")func fetchData(query:String){MovieDataManager.shared.fetchMovie(query: movieQuery.value){[weak self](movies)inguardlet self =selfelse{return}iflet movies = movies {
movies.forEach{letactor= $0.actor.removeString()letdirector= $0.director.removeString()lettitle= $0.title.removeString()letdata=MovieInfo(title: title , image: $0.image, director: director,actor:actor)self.downloadedMovies.value.movie +=[data]}}}}varnumOfRowInSection:Int{return downloadedMovies.value.movie.count
}func practiceCell(at indexPath:IndexPath){self.title.value =self.downloadedMovies.value.movie[indexPath.row].title
}func movieInfo(at index:Int)->MovieInfo{return downloadedMovies.value.movie[index]}}
Model
import Foundation
structMovie{varmovie:[MovieInfo]}structMovieInfo{lettitle:Stringletimage:Stringletdirector:Stringletactor:String}import Foundation
structMovieModel:Codable{letitems:[Movies]}structMovies:Codable{letimage:Stringlettitle:Stringletdirector:Stringletactor:String}
Helper
View
ViewModel
Model
APIManager
The text was updated successfully, but these errors were encountered: