WidgetKit and sendability problem

I'm having trouble with WidgetKit API, it doesn't seem to be adapted to modern Swift, unless I'm missing something of course.

In my TimelineProvider implementation I need to make async calls to my network methods:

private struct Provider: TimelineProvider {

	func getTimeline(in context: Context, completion: @escaping (Timeline<MyEntry>) -> ()) {
		Task {
			let entries = try await myAsyncMethod()
			completion(Timeline(entries: entries, policy: .atEnd)) // <- warning here

And I'm getting

Capture of 'completion' with non-sendable type '(Timeline) -> ()' in a @Sendable closure

There's probably a way of silencing this warning somehow (not sure exactly how) but there's no information what thread getTimeline is executed on, and how safe it is to silence the concurrency warnings. Also, @MainActor isn't helping.

How can this be resolved? Thanks!

Yes, seems like it hasn’t been update so far — completion has to be @Sendable. Right now you can try @preconcurrency either on import or protocol conformance.

Strangely @preconcurrency didn't help, neither with import nor with the protocol conformance.

(docs been confusing me lately) API has been updated with @Sendable in new Xcode, so you should be able to add it there safely: getTimeline(in:completion:) | Apple Developer Documentation

Thanks! So that's Xcode 16 beta, will have to wait (can't risk building for production on a beta).

If someone comes here with the same problem: for now and before Xcode 16 comes out, I set Strict Concurrency Checks to Targeted just for the widgets, hoping I won't break anything with bad concurrency.

    func getSnapshot(in context: Context, completion: @escaping @Sendable (MyEntry) -> Void) {
    func getTimeline(in context: Context, completion: @escaping @Sendable (Timeline< MyEntry >) -> Void) {

Hope this helps!

Doesn't work because those are protocol methods and their completion argument should be declared @Sendable in the protocol definition, not here. The compiler gives a warning on your solution and rightly so.