Supporting Older Versions of iOS and macOS
I recently answered a question from someone who wanted to know what version of Xcode and Swift to use to develop an app for iOS 9 and another question from someone who wanted to know what version of Xcode to use to develop an app to run on macOS 10.7. Answering what is basically the same question twice in one week is a sign that people are not sure how to make their apps run on older versions of iOS and macOS. This article should clarify things.
Short version: use the latest version of Xcode and set the deployment target for the project to the earliest version of iOS or macOS you want to support.
What Version of Xcode Should You Use?
You should use the most recent version of Xcode that will run on your Mac. Currently the most recent version of Xcode is version 10.1, which runs on macOS 10.13 and 10.14. The site Xcode Releases has a list of every Xcode release and the operating system requirements.
Why should you use the most recent Xcode version? Each version of Xcode ships with a SDK (Software Development Kit) for iOS and macOS. Xcode 10 ships with the iOS 12 and macOS 10.14 SDKs. The SDK contains the features your app can use. By using the latest SDK, your app can take advantage of the features Apple added in the latest version of iOS and macOS. The macOS 10.14 SDK includes support for dark mode. If you want your Mac app to look good in dark mode, you have to build it with the 10.14 SDK.
Some of you are asking the following question: if I use the iOS 12 SDK, will my app run only on devices running iOS 12? No. The SDK determines the latest features your app can take advantage of. The deployment target determines the operating systems that can run your app. If you use the iOS 12 SDK and set the deployment target to iOS 10, your app can run on devices running iOS 10, 11, and 12 (and future versions of iOS too).
What Version of Swift Should You Use?
All versions of Swift support the same operating systems: iOS 7 and later and macOS 10.9 and later. You can use the latest version of Swift and support older versions of iOS and macOS.
The main reason to use an older version of Swift is if you are using any non-Apple libraries or frameworks that were built with an older version of Swift. In that situation you should use the same version of Swift that was used to build the library or framework.
Setting the Deployment Target for Your Project
To make your app run on older versions of iOS and macOS, change the deployment target for your project by selecting the project file from the left side of the project window.
The deployment target is the earliest version of iOS or macOS that can run your app. Set the deployment target to the earliest version of iOS or macOS that you want to support. Keep in mind that Apple makes supporting earlier versions of iOS and macOS difficult. Most app developers support the most recent operating system version and the previous version, such as supporting iOS 11 and 12.
Setting the deployment target is mandatory for your app to run on older versions of iOS and macOS, but it’s not the only thing you have to do. You have to make sure your app isn’t using any technologies or calling any code that Apple introduced in a later iOS or macOS version. As an example Apple added a document browser class, UIDocumentBrowserViewController
, in iOS 11 to simplify creating and opening documents. If your app uses the new document browser, it will run only on iOS 11 and later. Setting the deployment target to iOS 9 isn’t going to make your document-based app run on iOS 9 or 10.
Summary
Use the latest version of Xcode so your app can take advantage of the latest features in iOS and macOS. Change the deployment target for your project to support earlier versions of iOS and macOS, making sure not to use any new technologies or functions.