periodic(from:by:)
A schedule for updating a timeline view at regular intervals.
Declaration
static func periodic(from startDate: Date, by interval: TimeInterval) -> PeriodicTimelineScheduleParameters
- startDate:
The date on which to start the sequence.
- interval:
The time interval between successive sequence entries.
Discussion
Initialize a TimelineView with a periodic timeline schedule when you want to schedule timeline view updates periodically with a custom interval:
TimelineView(.periodic(from: startDate, by: 3.0)) { context in
Text(context.date.description)
}The timeline view updates its content at the start date, and then again at dates separated in time by the interval amount, which is every three seconds in the example above. For a start date in the past, the view updates immediately, providing as context the date corresponding to the most recent interval boundary. The view then refreshes normally at subsequent interval boundaries. For a start date in the future, the view updates once with the current date, and then begins regular updates at the start date.
The schedule defines the PeriodicTimelineSchedule.Entries structure to return the sequence of dates when the timeline view calls the entries(from:mode:) method.