Timeline View in swift

By | June 13, 2024

The timeline view in Swift is a bit different, because it doesn’t have a display of its own. The main idea behind timeline view is that you can provide some kind of schedule and based on the schedule the view is going to get date and you can pass it to analog view or digital view of a timer view, whatever you want to do on a timely basis. It is available in iOS 15.

In below example we are using it to show a timer. It can be used for variety of tasks that needs to be executed on a timely basis.

struct ContentView: View {
    @State private var angle: Double = 0.0
    var body: some View {
        TimelineView(PeriodicTimelineSchedule(from: Date(), by: 1)) { context in
            Text("\(context.date.description)")
        }
    }
}

With the above code, we can create a timer that updates every second, as shown below.

Leave a Reply

Your email address will not be published. Required fields are marked *