Apple recently unified its operating system versioning by adopting year-based version numbers for the major releases of macOS, iOS, watchOS, tvOS, and visionOS. The operating systems that shipped in fall of 2025 all have an aligned version number of 26.0. Starting with the Swift 6.4 compiler, we’re taking advantage of this cross-platform version number alignment by introducing a new availability “platform” called anyAppleOS. This change will allow you to avoid boilerplate code when using new APIs and building for multiple Apple platforms.
To illustrate the improvement, here’s an example of code that iterates through a string's Unicode scalars via its utf8Span property:
// Swift Standard Library
extension String {
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *)
public var utf8Span: UTF8Span
}
// Example
func printScalarValues(_ string: borrowing String) {
if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) {
var iterator = string.utf8Span.makeUnicodeScalarIterator()
while let scalar = iterator.next() {
print(scalar.escaped(asASCII: true))
}
} else {
// Fallback on earlier versions...
}
}
printScalarValues("🎉") // Prints \u{0001F389}
Since this code deploys to older versions of all of Apple’s operating systems, an if #available check specifying five different operating system versions is needed to handle the case where String.utf8Span is not available at runtime. Using anyAppleOS we can simplify both the utf8Span declaration and the if #available check:
// Swift Standard Library
extension String {
@available(anyAppleOS 26.0, *) // 🆕
public var utf8Span: UTF8Span
}
// Example
func printScalarValues(_ string: borrowing String) {
if #available(anyAppleOS 26.0, *) { // 🆕
var iterator = string.utf8Span.makeUnicodeScalarIterator()
while let scalar = iterator.next() {
print(scalar.escaped(asASCII: true))
}
} else {
// Fallback on earlier versions...
}
}
Source compatibility
Availability specified using anyAppleOS is interchangeable with platform-specific availability. For example, when compiling Swift code for macOS, code guarded by macOS 26 availability can use declarations that are available in anyAppleOS 26 and vice-versa:
@available(macOS 26.0, *)
func availableInMacOS26()
@available(anyAppleOS 26.0, *)
func availableInAnyAppleOS26()
if #available(macOS 26.0, *) {
availableInMacOS26() // ✅
availableInAnyAppleOS26() // ✅ when building for macOS
}
if #available(anyAppleOS 26.0, *) {
availableInMacOS26() // ✅
availableInAnyAppleOS26() // ✅
}
This means that library authors can adopt anyAppleOS to simplify their API declarations without breaking source compatibility and API users can adopt anyAppleOS without waiting for updates to libraries.
Since the OS version alignment starts at version 26.0, it is invalid to specify an anyAppleOS version lower than 26.0:
if #available(anyAppleOS 25.0, *) { } // ❌ error: '25.0' is not a valid version number for any Apple OS
Combining anyAppleOS and platform-specific availability
For some Apple platforms, Swift infers availability when it isn’t explicitly specified. For example, by default macCatalyst and visionOS availability are inferred from iOS availability:
@available(iOS 18.0, *) // Inferred: macCatalyst 18.0, visionOS 2.0
func availableIniOS18()
This inference can be overridden by specifying explicit availability for those platforms instead:
@available(iOS 18.0, macCatalyst 18.1, visionOS 2.1, *)
func explicitAvailability()
As a general rule, when availability for multiple platforms is specified simultaneously, the compiler prefers the specification for the most specific platform that matches the compilation target.
Availability specified using anyAppleOS works the same way. The compiler infers platform-specific availability from anyAppleOS availability, but this inference can be overridden. For example, imagine an API that is introduced first on macOS 26, iOS 26, and visionOS 26 but is not initially available on either watchOS or tvOS:
@available(anyAppleOS 26.0, *)
@available(watchOS, unavailable)
@available(tvOS, unavailable)
public func newAPI()
If support for these APIs were added later in watchOS 26.4 and tvOS 26.4, the availability attributes could be updated like this:
@available(anyAppleOS 26.0, watchOS 26.4, tvOS 26.4, *)
public func newAPI()
Conditional compilation
anyAppleOS can be specified as an argument to #if os(...), simplifying conditional compilation in cross-platform code:
// Before
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
// ... code specific to macOS, iOS, watchOS, tvOS, or visionOS
#endif
// After
#if os(anyAppleOS)
// ... code specific to macOS, iOS, watchOS, tvOS, or visionOS
#endif
Interoperability
Clang will also support anyAppleOS availability, bringing the same availability simplification to C, Obj-C, and C++:
// Before
__attribute__((availability(macOS, introduced=26.0)))
__attribute__((availability(iOS, introduced=26.0)))
__attribute__((availability(watchOS, introduced=26.0)))
__attribute__((availability(tvOS, introduced=26.0)))
__attribute__((availability(visionOS, introduced=26.0)))
@interface NewIn26
// ...
@end
// After
__attribute__((availability(anyAppleOS, introduced=26.0)))
@interface NewIn26
// ...
@end
Clang availability attributes that specify anyAppleOS availability are imported into Swift as you would expect.
Trying it out
anyAppleOS support is available for you to try in the latest Swift.org toolchain snapshots built from main.