Skip to content

Instantly share code, notes, and snippets.

@ykpoh
Last active August 15, 2021 04:49
Show Gist options
  • Save ykpoh/9dbe8fb1dc9338e893af15f08ac905bc to your computer and use it in GitHub Desktop.
Save ykpoh/9dbe8fb1dc9338e893af15f08ac905bc to your computer and use it in GitHub Desktop.
struct Provider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), building: .barrack)
}
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), building: .barrack)
completion(entry)
}
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let endDate = selectedBuilding.completionDate
let oneMinute: TimeInterval = 60
var currentDate = Date()
var entries: [SimpleEntry] = []
while currentDate < endDate {
let progress = selectedBuilding.getCurrentProgress(startDate, endDate)
let entry = SimpleEntry(date: currentDate, progress: progress)
currentDate += oneMinute
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