Skip to content

Instantly share code, notes, and snippets.

@jamesrochabrun
Last active July 23, 2020 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesrochabrun/c92a8470676cd05f0b7850a17d8c8cf8 to your computer and use it in GitHub Desktop.
Save jamesrochabrun/c92a8470676cd05f0b7850a17d8c8cf8 to your computer and use it in GitHub Desktop.
// 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