0

Sorry if this has already been asked, but would like to understand in detail as it has created huge dependencies on all my Swift apps.

With most of the Swift version updates there is Xcode version which is tightly coupled with it.

For example if I create a framework with Swift 4.0.3 using Xcode 9.2, it does not compile with Xcode 9.3/9.4 or upcoming Xcode 10, which I understand as Swift itself is evolving and no complier can provide forward compatibility.

But would like to know any one of you treat this problem in different way is there some short route that I am completely missing.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Rein rPavi
  • 3,368
  • 4
  • 22
  • 32

2 Answers2

2

This situation will get a lot better after we reach Swift 5. Until then, all you can do is live with it, updating every time you update to a new version of Swift. Two suggestions:

  • Your life is made a little easier in recent Swift versions because you can use conditional compilation with #if and a condition like swift(>=4.2) or (starting in Swift 4.2) compiler(>=4.2), so that you can talk different ways depend what version of Swift we're compiling under.

  • Language version is a build setting, per target. So the coupling is not completely tight; if you're using older code, you can continue (to some extent) to use an older version of the language. This screen shot is from Xcode 10, showing that you can compile Swift 4.0 code:

    enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

This is not necessarily an answer of sorts, but you do have the ability to work with varying Swift versions in newer (see this answer for more detail). My approach has always been to keep up to date with the latest Xcode releases, be them via the Mac App Store or Developer Downloads, and run a copy of my project to determine what changes are coming.

The changes between earlier versions of Swift (1.0 -> 2.0) were incredibly jarring. The changes from Swift 4.0.3 -> 4.1 (or even 4.2) are not as drastic, and while still critical to the development of the language, Xcode now does a far better job of suggesting how to update your code.

In short, there is not necessarily a short route (that I'm aware of), but you may find yourself in a better position by constantly evaluating your current code in newer Xcode versions and deciding how and when to make the move to the newer language.

ZbadhabitZ
  • 2,753
  • 1
  • 25
  • 45