Possible to return an AsyncSequence<T> for iOS 17 when building against iOS 18?

AsyncSequence got changed in iOS 18, and now I can't figure out how to use it as a return type in a way that works with both 17 and 18.

Example:

func subscribe() -> any AsyncSequence<String>  { ... }

Gives Error: Protocol type 'AsyncSequence' specialized with too few type arguments (got 1, but expected 2)

But this:

func subscribe() -> any AsyncSequence<String, Never> { ... }

Gives Error: 'Failure' is only available in iOS 18.0 or newer

Which I can fix by adding in @available(iOS 18.0, *) -- but now I am back to having no iOS 17 API.

... I feel like there has to be an obvious, simple answer that I am just not seeing?

There might be some ideas here that could help.

1 Like