Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created November 9, 2022 17:09
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 BetterProgramming/f1d1ae28e579bd4f64f738d6e45bdc1b to your computer and use it in GitHub Desktop.
Save BetterProgramming/f1d1ae28e579bd4f64f738d6e45bdc1b to your computer and use it in GitHub Desktop.
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [QuoteEntry] = []
// Generate a timeline consisting of five entries minute apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 5 {
let quote = quoteManager.getSingleQuote()
let entryDate = Calendar.current.date(byAdding: .minute, value: hourOffset, to: currentDate)!
let entry = QuoteEntry(date: entryDate, quote: quote)
entries.append(entry)
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment