Hey, I'm giving a first go at the brand new iOS 14 Widgets. I tried setting up a very simple widget (directly taken from both the documentation examples and the default generated project).
Right now my goal is to have a simple widget that :
In this example I'm trying to have a refresh every 15 minutes, but when ran on simulator, the widget seems to update continuously and random numbers keep getting re-drawn. Like almost 8-9 per second. My print line gets displayed non stop too.
Any idea what I'm doing wrong ?
Right now my goal is to have a simple widget that :
Refreshes every 10 seconds
Displays a random number on every refresh
Code Block swift struct Provider: TimelineProvider { public typealias Entry = SimpleEntry public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(status: "Populating", date: Date()) completion(entry) } public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) { print("Going through timeline.") let date = Date() let entry = SimpleEntry(status: String(Int.random(in: 0 ..< 10)), date: date) let nextUpdateDate = Calendar.current.date(byAdding: .minute, value: 15, to: date)! let timeline = Timeline( entries: [entry], policy: .after(nextUpdateDate) ) completion(timeline) } } struct SimpleEntry: TimelineEntry { public let status: String public let date: Date } struct PlaceholderView : View { var body: some View { Text("Placeholder View") } } struct WidgetAdventureWidgetExtensionEntryView : View { var entry: Provider.Entry var body: some View { Text(entry.status) } }
In this example I'm trying to have a refresh every 15 minutes, but when ran on simulator, the widget seems to update continuously and random numbers keep getting re-drawn. Like almost 8-9 per second. My print line gets displayed non stop too.
Any idea what I'm doing wrong ?