Last active
August 15, 2021 04:49
-
-
Save ykpoh/9dbe8fb1dc9338e893af15f08ac905bc 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 { | |
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