Created
September 7, 2020 04:04
-
-
Save pallavtrivedi03/ea4dae93d15b96a1198afe48d556ecba 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
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