Skip to content

Instantly share code, notes, and snippets.

@pallavtrivedi03
Created September 7, 2020 04:04
Show Gist options
  • Save pallavtrivedi03/ea4dae93d15b96a1198afe48d556ecba to your computer and use it in GitHub Desktop.
Save pallavtrivedi03/ea4dae93d15b96a1198afe48d556ecba to your computer and use it in GitHub Desktop.
struct Provider: TimelineProvider {
let dummyData = MovieInfo(name: "Some latest movie", releaseDate: "Release Date", daysSinceRelease: 1, collection: "Collection in Cr", posterUrl: "https://popcornusa.s3.amazonaws.com/placeholder-movieimage.png")
func placeholder(in context: Context) -> MovieInfoEntry {
MovieInfoEntry(date: Date(), movieInfo: dummyData)
}
func getSnapshot(in context: Context, completion: @escaping (MovieInfoEntry) -> ()) {
let entry = MovieInfoEntry(date: Date(), movieInfo: dummyData)
completion(entry)
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let currentDate = Date()
let refreshDate = Calendar.current.date(byAdding: .minute, value: 1, to: currentDate)!
MovieInfoLoader.fetch { result in
var movie: MovieInfo
if case .success(let fetchedMovies) = result {
movie = fetchedMovies.randomElement()!
} else {
movie = MovieInfo(name: "Some latest movie", releaseDate: "Release Date", daysSinceRelease: 1, collection: "Collection in Cr", posterUrl: "https://popcornusa.s3.amazonaws.com/placeholder-movieimage.png")
}
let entry = MovieInfoEntry(date: currentDate, movieInfo: movie)
let timeline = Timeline(entries: [entry], policy: .after(refreshDate))
completion(timeline)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment