What’s the correct way to implement getTimelineEndDate(for:withHandler:)?

Maybe I’m getting this all wrong.

The video says…
Code Block
handler(timeline(for: complication)?.endDate)

(but it doesn’t indicate how / if this .endDate is set. Why would one write to a timeline.endDate inside the func if it is set by this func? What is the timeline var anyway?

the docs say
Code Block
handler(Date().addingTimeInterval(24.0 * 60.0 * 60.0))

but there is no switch for complication.

Now I’m thinking: switching by complication one can chose which endDate to handle. Is that correct?

Answered by Frameworks Engineer in 661132022
I imagine that the video you mention here is this one Create complications for Apple Watch.

The intention of the snippet you've got
Code Block
handler(timeline(for: complication)?.endDate)
doesn't really cover how you get endDate because that's up to your complication. In this case, timeline(for:) is a function that you've written yourself that provides the endDate for that particular complication.

Now I’m thinking: switching by complication one can chose which endDate to handle. Is that correct?

Yep! You can get all the information you need to figure out which complication is being asked about specifically from its identifier and family. You can switch on those and provide the endDate that works for you.


Accepted Answer
I imagine that the video you mention here is this one Create complications for Apple Watch.

The intention of the snippet you've got
Code Block
handler(timeline(for: complication)?.endDate)
doesn't really cover how you get endDate because that's up to your complication. In this case, timeline(for:) is a function that you've written yourself that provides the endDate for that particular complication.

Now I’m thinking: switching by complication one can chose which endDate to handle. Is that correct?

Yep! You can get all the information you need to figure out which complication is being asked about specifically from its identifier and family. You can switch on those and provide the endDate that works for you.


Thx.
What’s the correct way to implement getTimelineEndDate(for:withHandler:)?
 
 
Q