7

I'm kinda new to Swift (less than 1 full year), and I'm not sure how to update to latest Swift within the new Xcode each year. My project has been started under Xcode 8 and Swift 3.2. Now I upgraded Xcode 9, which AFAIU supports Swift 4.

Since I'm using Cocoapods, I obviously updated all pods to their latest versions, which I believe is correct behavior.

However, I see that the Swift version in target settings is still set to Swift 3.2. What exactly does that mean? Should I change it to Swift 4 instead? Or that's just like minimum version that I have to write code according to?

Also, I have 2 warnings in the project:

enter image description here

Regardings Pods, it is clear that Cocoapods will fix that, so np.

What about my Workspace? My target builds fine without errors and warnings, I'm not sure why it tells me about conversion? Shouldn't it tell an exact line in the file with code instead?

Please, describe what is the correct flow of update to latest Swift in general, and how this works with some of pods that are not updating to the latest Swift each year. Will I be forced to remove them, or like fork and update to latest Swift manually?

Krunal
  • 77,632
  • 48
  • 245
  • 261
Stas Ivanov
  • 917
  • 1
  • 10
  • 22

2 Answers2

7

Upgrading Xcode version, will not change/upgrade your Swift programming language version. These warning show, your current Swift programming language version is not 4.0 (it is below 4.0 i.e. 3.2).

(Also note, Xcode 9 and 8.3 both support Swift 3.2. You can work with Xcode 9 using Swift 3.2 also.)

So, if you open your Xcode 8.x project in Xcode 9, will work with Swift version 3.2.

Manually you need to change Swift 3.2 to 4.0 from project build settings.

Here is - How to see current Swift language version and change it to newer.

enter image description here

Also note: Once you change your swift language ensure following steps:

  • You must update/upgrade your cocoa pod (CocoaPods)
  • Update your project's pod libs/files (using command pod install or pod update)

For easier migration refer these answers:

(Xcode) Menus: Edit ► Covert ► To Current Swift Syntax

enter image description here

Community
  • 1
  • 1
Krunal
  • 77,632
  • 48
  • 245
  • 261
  • IC, but anyway for future Xcode 10, I guess, it is better to update to Swift 4. Regarding updating pods I have a question. So what if pod is not updated to Swift 4? Will I be able to use it? Or I will have to downgrade project/target to Swift 3.2? – Stas Ivanov Oct 18 '17 at 10:39
  • @StasIvanov yes, pod will automatically identifies your cocoa pod version and Swift programming language version. And automatically download relevant files/libs from sources – Krunal Oct 18 '17 at 10:41
  • @StasIvanov As of now, it would be better to work with Swift 3.2 (not to go with 4.0) for existing projects. You can choose Swift 4.0 for new projects. – Krunal Oct 18 '17 at 10:42
  • but if I will have some pod that doesn't support even 3.2, and just 3.1 or lower, then I must to remove them or find alternatives, right? So, just for my better understanding: Since Xcode does support Swift 4 and Swift 3.2, I can still work as before, cause all my pods are valid for this. Also, in case I migrate project and code to Swift 4 right now, I still will be able to use libs with Swift 3.2. But for future Xcode, in case it won't support Swift 3.2, I will have to get rid of old pods etc. Right? – Stas Ivanov Oct 18 '17 at 10:50
  • @StasIvanov No, you may not need to remove. Try to look into pod version release list, there should be pod supporting 3.2 and 4.0 also. Share me pod name that you can't find for 3.2. I'll provide you relevant link/pod name to integrate in your pod file. – Krunal Oct 18 '17 at 10:54
  • no, I understand that probably there can be different branches for the same pod for different Swift versions. I don't have an exact example right now, but I'm interested in case I have very old pod that have only Swift 2 version, and that's it. Can I use it with Swift 3.2 or Swift 4? Or it is not backward compatible? – Stas Ivanov Oct 18 '17 at 13:24
  • 1
    No, your project must have pod files/libs compatible to your current swift version. Pod with support of/till Swift 2, will not work in Swift 3+. – Krunal Oct 18 '17 at 13:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/157013/discussion-between-stas-ivanov-and-krunal). – Stas Ivanov Oct 18 '17 at 15:22
1

You don't have to convert your project to the Swift 4, the Xcode 9 supports Swift 3.2 as well.

If you want to convert your project to the Swift 4, use:

  • Edit -> convert -> To Current Swift Syntax

You can also use both versions (e.g. some pods don't have to be ready for Swift 4 yet). Check/set your target's version in Building settings - Swift language version

Jakub Truhlář
  • 20,070
  • 9
  • 74
  • 84