(I'm using Xcode 16 beta on macOS 14.5)
How do I get this to compile for both macOS 15 and macOS 14? :
public final class EmitterOfEvents {
public typealias Element = Int
public func notifications() -> some AsyncSequence<Element, Never> {
AsyncStream<Element>.makeStream().stream
}
}
I get error:
I'm well aware of SE-0421, and I'm excited about the change. Hopefully I'm just a bit tired right now and what I want is possible, but it feels like something is missing?
I cannot use:
@available(macOS 15.0, *)
public func notifications() -> some AsyncSequence<Element, Never> {
AsyncStream<Element>.makeStream().stream
}
Since the method notifications()
must exist and work on macOS 14 too.
I cannot use if #available(macOS 15.0, *) {
since that is put inside the body, and my problem is the return type...
I try:
#if swift(>=6.0)
public typealias Notifications = AsyncSequence<Element, Never>
#else
public typealias Notifications = AsyncSequence<Element>
#endif
That does not work either:
So Swift version is the "wrong dimension".
I guess I want #if os(macOS 15.0, *)
, which is discussed here, but that does not exist.
So I try to find some macOS 15 only new SDK but could not find any... so I cannot use the canImport(NewFancyMacOS15OnlyKit)
"trick" either. hmm...
This is in an SPM proj btw, can I do something clever in Package.swift, to create some macOS version dependent variable?
So can I use @available
and create two different versions of notifications()
with different return types? Hmm does not seem to be possible to spell "else" for @available
?
So what to do? hopefully I've missed something :)