每次寫新功能都要寫判斷 ios26以上才能用新功能 否則就要重寫一次適合舊版本的內容。有沒有什麼辦法可以讓我直接寫適用新版本的code,不能套用的話自動回退到舊版本
Asked on 06/12/2025
1 search
To address the challenge of writing code that works on iOS 26 and automatically falls back to older versions if necessary, you can leverage some of the new features and best practices introduced at WWDC 2025. Here are a few strategies:
-
Use Conditional Compilation: Swift allows you to use conditional compilation to include or exclude code based on the platform or version. This can help you write code that only runs on iOS 26 or later.
-
Adopt New APIs with Fallbacks: When using new APIs, you can provide fallback implementations for older versions. This ensures that your app remains functional even if certain features are not available.
-
Runtime API Checks: Xcode 26 introduces more runtime API checks, which can help you identify and handle issues related to API availability. This can be configured in the Test Plan Configuration Editor. For more details, you can refer to the session What’s new in Xcode (30:15).
-
Automatic Observation Tracking: UIKit now integrates Swift observation at its core, which can be back-deployed to iOS 18 by adding a specific key to your Info.plist. This allows you to use new observation features while maintaining compatibility with older versions. More information can be found in the session What’s new in UIKit (10:21).
By using these techniques, you can write code that takes advantage of new features in iOS 26 while ensuring compatibility with older versions.

Platforms State of the Union
Discover the newest advancements on Apple platforms.

What’s new in Xcode
Discover the latest productivity and performance advancements in Xcode 26. Learn how to leverage large language models in your development workflow. Explore editing and debugging enhancements, improved performance and testing tools, and Swift Build - the open-source build system engine used by Xcode.

What’s new in UIKit
Modernize your app with the latest APIs in UIKit, including enhanced menu bar support, automatic observation tracking, a new UI update method, and improvements to animations. We’ll also cover how you can include SwiftUI scenes in your UIKit app and explore SF Symbols, HDR color pickers, and more.