Search code examples
iosswiftxcodexcode9swift4

Update to Xcode 9 and Swift 4


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?


Solution

  • 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