Nutrient

Home

SDK

Software Development Kits

Low-Code

IT Document Solutions

Workflow

Workflow Automation Platform

DWS API

Document Web Services

T
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Company

About

Team

Careers

Contact

Security

Partners

Legal

Resources

Blog

Events

Try for free

Contact Sales
Contact sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

products

Web

Web

Document Authoring

AI Assistant

Salesforce

Mobile

iOS

Android

visionOS

Flutter

React Native

MAUI

Server

Document Engine

Document Converter Services

.NET

Java

Node.js

AIDocument Processing

All products

solutions

USECASES

Viewing

Editing

OCR and Data Extraction

Signing

Forms

Scanning & Barcodes

Markup

Generation

Document Conversion

Redaction

Intelligent Doc. Processing

Collaboration

Authoring

Security

INdustries

Aviation

Construction

Education

Financial Services

Government

Healthcare

Legal

Life Sciences

All Solutions

Docs

Guides overview

Web

AIAssistant

Document Engine

iOS

Android

visionOS

Java

Node.js

.NET

Document Converter Services

Downloads

Demo

Support

Log in

Resources

Blog

Events

Pricing

Try for free

Free Trial

Company

About

Security

Partners

Legal

Contact Sales
Contact Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

products

Products overview

Document Converter

Document Editor

Document Searchability

Document Automation Server

Integrations

SharePoint

Power Automate

Nintex

OneDrive

Teams

Window Servers

solutions

USECASES

Conversion

Editing

OCR Data Extraction

Tagging

Security Compliance

Workflow Automation

Solutions For

Overview

Legal

Public Sector

Finance

All Solutions

resources

Help center

Document Converter

Document Editor

Document Searchability

Document Automation Server

learn

Blog

Customer stories

Events

Support

Log in

Pricing

Try for free

Company

About

Security

Partners

Legal

Contact Sales
Contact Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Product

Product overview

Process Builder

Form Designer

Document Viewer

Office Templating

Customization

Reporting

solutions

Industries

Healthcare

Financial

Manufacturing

Pharma

Education

Construction

Nonprofit

Local Government

Food and Beverage

Departments

ITServices

Finance

Compliance

Human Resources

Sales

Marketing

Services

Overview

Capex-accelerator

Process Consulting

Workflow Prototype

All Solutions

resources

Help center

guides

Admin guides

End user guides

Workflow templates

Form templates

Training

learn

Blog

Customer stories

Events

Support

Pricing

Support

Company

About

Security

Partners

Legal

Try for Free
Contact Sales
Try for Free
Contact Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Services

Generation

Editing

Conversion

Watermarking

OCR

Table Extraction

Pricing

Docs

Log in

Try for Free
Try for Free

Free trial

Blog post

Conditional Compilation for Apple’s Yearly Updates

Douglas Hill Douglas Hill

Table of contents

  • Expectations of Apple
  • The Problem
  • The Solution
  • Conclusion
Illustration: Conditional Compilation for Apple’s Yearly Updates

Over the last several years, Apple has settled into a consistent cycle with updates to its platforms. The company won’t publicly commit to future plans, but as a software developer on Apple platforms, it’s important to know what to expect to plan your work. Apple doesn’t release all its yearly operating system updates at the same time, so some special considerations are needed for cross-platform apps — which is what this article will explore.

This post comes from our perspective of having a codebase using UIKit and SwiftUI with the iOS SDK and the Mac Catalyst SDK. While I won’t mention the macOS SDK (for AppKit and SwiftUI), the issues and solution outlined in this post are also applicable there. If your codebase only supports one platform, then the situation is a little simpler for you.

Expectations of Apple

This is what we can expect, based on Apple’s pattern from the previous few years:

  • In June, Apple is expected to release the first betas of iOS 17, macOS 14 and Xcode 15, which will use the iOS 17 and Mac Catalyst 17 SDKs. Meanwhile, Xcode 14 will remain the stable release of Xcode, which uses the iOS 16 and Mac Catalyst 16 SDKs.

  • In September, Apple is expected to release the public version of iOS 17 and Xcode 15.0, which will continue using the iOS 17 SDK. However, crucially, Apple won’t release the public version of macOS 14, and correspondingly, Xcode 15.0 will revert to using the Mac Catalyst 16 SDK.

  • In October, Apple is expected to release the public version of macOS 14 and Xcode 15.1, which will bring back using the Mac Catalyst 17 SDK.

This table summarises what happened last year:

iOS SDK Mac Catalyst SDK Swift Version
Xcode 13.4 15.5 15.5 5.6
Xcode 14.0 beta 16.0 16.0 5.7
Xcode 14.0 RC 16.0 15.5 5.7
Xcode 14.1 16.0 16.0 5.7

The Problem

If we started using APIs that were added in the new iOS SDK when the beta version of Xcode was available, we’d get a nasty surprise when the final .0 version of Xcode came out: Our code would stop compiling for Mac. We’d also no longer be able compile with the old version of Xcode, due to new APIs being missing from the old SDK.

Between June and October, we want to achieve the following:

  • We want to use new APIs introduced in the iOS 17 SDK to benefit from new iOS 17 features. We want to start testing these before the public release of iOS 17.

  • We want our codebase to continue to compile and run with the older version of Xcode so that we can reproduce issues reported in production and ship updates.

  • We don’t want to require all our personnel to update Xcode at precisely the same time. This includes not just our iOS team, but also our Core team, Hybrids team, Support team and more.

  • We don’t want the overhead of managing different branches in our version control system for different versions of Xcode.

The Solution

To use new APIs, we need two different types of checks:

  • A compile-time check that the APIs are available in the SDK our code is being linked with.

  • A runtime check that the APIs are available in the version of the OS our code is running on.

Compile-Time Check

The compile-time check is the trickier part, so let’s look at that first. Swift’s conditional compilation blocks support these conditions:

  • os — Target operating system platform

  • arch — CPU architecture

  • swift — Swift language version

  • compiler — Swift compiler version

  • canImport — Whether a framework/module is available

  • targetEnvironment — Whether the target is a simulator or is Mac Catalyst

There’s no check for the version of the SDK that the code is being linked with.

We considered if we could use the Swift version. This would work if iOS is your only platform, but it doesn’t work for the Mac where the SDK version is reverted in the final .0 Xcode release but the Swift version isn’t.

Since each new version of Apple’s SDKs tends to include several new frameworks (modules), we can use the workaround of checking whether one of these modules is available. Last year, in 2022, we picked RoomPlan. It’s incredibly cool tech, but we don’t actually use or plan to use RoomPlan anywhere in our codebase, which will make it easy to search for when we can remove these checks later on:

#if canImport(RoomPlan)
// We're linking with the new version of the SDK, but we might be running on either a new or old version of the OS.
#else
// We're linking with the old version of the SDK.
#endif

If we compiled using the old version of Xcode or the final .0 new version on Mac, RoomPlan wouldn’t be available, so only the code between #else and #endif would be compiled. In other scenarios, our code would be linked with the new SDK, meaning RoomPlan would be available, so the first block of code would be complied.

Runtime Check

To check the version of the OS our code is running on, we use a Swift availability condition like this:

if #available(iOS 16.0, *) {
    // Use new APIs.
} else {
    // New APIs aren't available.
}

Putting These Together

Putting these two checks together, we ended up with this code for last year’s updates (in 2022):

#if canImport(RoomPlan)
if #available(iOS 16.0, *) {
    // Use new APIs.
} else {
    // Provide fallback behavior when compiling with the newer Xcode but running on an older version of the OS.
}
#else
// Provide fallback behavior when compiling with an Xcode version using the old SDK.
#endif

In most cases, the fallback code will be identical. Unfortunately, there’s no way to structure this to avoid repeating a small amount of code.

Here’s a trivial example showing using the preferredMenuElementOrder property of UIButton that was added in the iOS 16 SDK. We use this new API, if it’s available, to ask the menu to show its actions with the first action at the top, even if the menu appears upward from the button. On older versions, we can implement this behaviour by manually reversing the order of our menu actions:

var actions: [UIAction] = ...
let button = UIButton()
button.showsMenuAsPrimaryAction = true
#if canImport(RoomPlan) // iOS 16.0 SDK
if #available(iOS 16.0, *) {
    button.preferredMenuElementOrder = .fixed
} else {
    actions.reverse()
}
#else
actions.reverse()
#endif
button.menu = UIMenu(children: actions)

With this, all our goals are met, and we could even leave these checks in our codebase indefinitely. Once all our personnel update to the .1 of the new Xcode version, the #else block will simply never be compiled, so we can clean this up at a time that suits us.

What about Objective-C?

These checks are more obvious in Objective-C because we can directly check the version of the SDK being linked with:

#if __IPHONE_16_0
if (@available(iOS 16.0, *)) {
    // Use new APIs.
} else {
    // Provide fallback behavior when compiling with the newer Xcode but running on an older version of the OS.
}
#else
// Provide fallback behavior when compiling with an Xcode version using the old SDK.
#endif

Conclusion

In this post, we’ve seen the problem of supporting new features in Apple’s OS updates while still having our code compile with the stable or older version of Xcode. We need both a compile-time check and a runtime check. To make the compile-time check in Swift, we use the canImport condition with an arbitrary module that was added in the newer SDK version. This allows everyone on the team to use whichever version of Xcode they need for a particular task. That way, there’s no need to worry about version control conflicts or working on the wrong branch.

Author
Douglas Hill
Douglas Hill iOS Team Lead

Douglas makes the most of our fully remote setup by frequently traveling around Europe by train. He’s a proponent of iPad as a productivity platform and is obsessive about the details of great user experiences. He’s also an organizer of the NSLondon meetup.

Explore related topics

iOS Insights Xcode Development
Free trial Ready to get started?
Free trial

Related articles

Explore more
SDKDEVELOPMENTTUTORIALSiOSAndroidWebHow ToPDF

Understanding fonts in PDFs: A comprehensive guide

SDKRELEASESNutrient AI AssistantNutrient iOS SDKNutrient Android SDKiOSAndroid

AI Assistant for iOS and Android: Intelligent document interaction, now in your users’ pockets

SDKINSIGHTSiOSInsightsXcodeDevelopment

Life on the iOS team at Nutrient: Building for the long term

Company
About
Security
Team
Careers
We're hiring
Partners
Legal
Products
SDK
Low-Code
Workflow
DWS API
resources
Blog
Events
Customer Stories
Tutorials
News
connect
Contact
LinkedIn
YouTube
Discord
X
Facebook
Popular
Java PDF Library
Tag Text
PDF SDK Viewer
Tag Text
React Native PDF SDK
Tag Text
PDF SDK
Tag Text
iOS PDF Viewer
Tag Text
PDF Viewer SDK/Library
Tag Text
PDF Generation
Tag Text
SDK
Web
Tag Text
Mobile/VR
Tag Text
Server
Tag Text
Use Cases
Tag Text
Industries
Tag Text
Resources
Blog
Tag Text
Events
Customer Stories
Tag Text
Tutorials
Tag Text
Features List
Tag Text
Compare
Tag Text
community
Free Trial
Tag Text
Documentation
Tag Text
Nutrient Portal
Tag Text
Contact Support
Tag Text
Company
About
Tag Text
Security
Tag Text
Careers
Tag Text
Legal
Tag Text
Pricing
Tag Text
Partners
Tag Text
connect
Contact
Tag Text
LinkedIn
Tag Text
YouTube
Tag Text
Discord
Tag Text
X
Tag Text
Facebook
Tag Text
low-code
Document Converter
Tag Text
Document Editor
Tag Text
Document Automation Server
Tag Text
Document Searchability
Tag Text
Use Cases
Tag Text
Industries
Tag Text
Resources
Blog
Tag Text
Events
Customer Stories
Tag Text
Support
Help Center
Tag Text
Contact Support
Tag Text
Log In
Tag Text
Company
About
Tag Text
Careers
Tag Text
Security
Tag Text
Legal
Tag Text
Pricing
Tag Text
Partners
Tag Text
connect
Contact
Tag Text
LinkedIn
Tag Text
YouTube
Tag Text
Discord
Tag Text
X
Tag Text
Facebook
Tag Text
Popular
Approvals matrix
Tag Text
BPMS
Tag Text
Budgeting process
Tag Text
CapEx approval
Tag Text
CapEx automation
Tag Text
Document approval
Tag Text
Task automation
Tag Text
workflow
Overview
Tag Text
Services
Tag Text
Industries
Tag Text
Departments
Tag Text
Resources
Blog
Tag Text
Events
Customer Stories
Tag Text
Support
Help Center
Tag Text
FAQ
Tag Text
Troubleshooting
Tag Text
Contact Support
Tag Text
Company
About
Tag Text
Careers
Tag Text
Security
Tag Text
Legal
Tag Text
Pricing
Tag Text
Partners
Tag Text
connect
Contact
Tag Text
LinkedIn
Tag Text
YouTube
Tag Text
Discord
Tag Text
X
Tag Text
Facebook
Tag Text
DWS api
PDF Generator
Tag Text
Editor
Tag Text
Converter API
Tag Text
Watermark
Tag Text
OCR
Tag Text
Table Extraction
Tag Text
Resources
Log in
Tag Text
Help Center
Tag Text
Support
Tag Text
Blog
Tag Text
Company
About
Tag Text
Careers
Tag Text
Security
Tag Text
Pricing
Tag Text
Legal
Privacy
Tag Text
Terms
Tag Text
connect
Contact
Tag Text
X
Tag Text
YouTube
Tag Text
Discord
Tag Text
LinkedIn
Tag Text
Facebook
Tag Text

Copyright 2025 Nutrient. All rights reserved.

Thank you for subscribing to our newsletter!

We’re thrilled to have you join our community. You’re now one step closer to receiving the latest updates, exclusive content, and special offers directly in your inbox.

This builtin is not currently supported: DOM

PSPDFKit is now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

This builtin is not currently supported: DOM

PSPDFKit is now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

This builtin is not currently supported: DOM

New Feature Release. Tap into revolutionary AI technology to instantly complete tasks, analyze text, and redact key information across your documents. Learn More or View Showcase

This builtin is not currently supported: DOM

Aquaforest and Muhimbi are now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

This builtin is not currently supported: DOM

Integrify is now Nutrient. We've consolidated our group of trusted companies into one unified brand: Nutrient. Learn more

This builtin is not currently supported: DOM

Join us on April 15th. Join industry leaders, product experts, and fellow professionals at our exclusive user conference. Register for conference