Last active
July 23, 2020 01:24
-
-
Save jamesrochabrun/c92a8470676cd05f0b7850a17d8c8cf8 to your computer and use it in GitHub Desktop.
This file contains 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
// 1 | |
final class MoviesProvider: ObservableObject { | |
// MARK:- Subscribers | |
// 2 | |
private var cancellable: AnyCancellable? | |
// MARK:- Publishers | |
// 3 | |
@Published var movies: [MovieViewModel] = [] | |
// MARK:- Private properties | |
// 4 | |
private let client = MovieClient() | |
init() { | |
// 5 | |
cancellable = client.getFeed(.nowPlaying) | |
.sink(receiveCompletion: { _ in }, | |
receiveValue: { | |
self.movies = $0.results.map { MovieViewModel(movie: $0) } | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment