How can I update swift from 3.1 to 3.2, but not to 4.0
Asked Answered
K

5

12

I have checked the question related to how to find the current Swift version by the command swift --version, but how can I upgrade my Swift version from 3.1 to 3.2? (because the Xcode 9 only supports Swift 4.0 & Swift 3.2)

To build successfully both in Xcode 8 & Xcode 9, it's better to upgrade Swift from 3.1 to 3.2. But how?

My target was to make sure build successfully both in Xcode 8 & Xcode 9, So that publish with Xcode 8 would be OK, and try out the feature of Xcode 9 is OK too. So I will not upgrade code to swift 4.0 yet until Xcode 9.0 official edition is published.

After my test, I can't convert my code from swift 3.1 to 3.2 by Xcode 8.3.3's 'edit->convert' function.

enter image description here

The reason why I try to convert the code to Swift 3.2 is that I will get error of "Module compiled with Swift 3.1 cannot be imported in Swift 4.0" if I build the code with Xcode 9.

enter image description here

Kobylak answered 8/6, 2017 at 9:6 Comment(4)
Swift 3.2 is not included in Xcode 8.3.3, so you can not convert to Swift 3.2 in Xcode 8.3.3.Heckle
Have you tried cleaning your build folder? Maybe it's not a conversion thing but the fact that something in the build folder was built with Xcode 8.Sludge
Hi, Were you able to convert it ? Right now my app is working fine in xcode 8(Swift 3) . Should I convert it to swift 3.2 before converting to swift 4 in xcode 9? So which xcode should I download to covert it to swift 3.3? Any tips would be really helpfulMcdevitt
@PruthviHariharan Use XCode9.1 and make sure Command Line Tools switch to XCode9.1(9B55), Build Settings->Swift Language Version point to Swift 3.2. Then remove all content under folder of DerivedData, and clean & build to check, then fix the build errors & warnings show in XCode 9.1. That's it. The step after this would be update to support swift4, but which may take more time.Kobylak
A
7

You can try this:

  • Build Settings -> Swift Langauge Version -> Swift 3.2.

enter image description here

  • Edit -> Convert -> To Current Swift Syntax.

Noted: These step using Xcode 9

Aglet answered 13/6, 2017 at 9:50 Comment(1)
I think I have already try this. But not work as remember. But I can have a try again later.Kobylak
H
6

Swift 3.2 is a stopgap solution to continue using Swift 3 code under Xcode 9 without fully converting projects to Swift 4.

The Swift version included in Xcode 8.3.3 is 3.1. Converting your code to Swift 3.2 under Xcode 9 does not guarantee that it will still compile under Xcode 8.

I'm not sure compiling Swift 3.1 code as Swift 3.2 under Xcode 9 requires any conversion at all, since they both share the same syntax. You may have to fix some API calls to compensate for changes in the new SDKs.

Apple has a little more information here:

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Compatibility.html

(updated)

Regarding your last image, if you have the source code for the Runes module, you'll have to recompile it under Xcode 9. That will make use of Swift 3.2 and allow it to be imported in Swift 4.

Heckle answered 8/6, 2017 at 9:26 Comment(1)
After test, I can't convert from swift 3.1 to 3.2. so sad.Kobylak
U
2

Dependency modules/ frameworks in swift have to be recompiled w/ xcode9 since swift is not ABI compatible/ stable. If you have included dependencies using package distribution systems like carthage or cocoa pods, the modules would be recompiled w/ xcode9 and you shouldn't see this issue. If you are linking packages built distributed in binary format, then you can run into the issue

Unreliable answered 9/6, 2017 at 14:13 Comment(1)
Yes, I understand your point. I just wonder if I can really build all things with swift 3.2, then I should be able to run the code both with Xcode 8 & 9 without rebuild these. Right? Otherwise it was tough working on it both migrate & support original release plan by switch Xcode8 & 9 frequently.Kobylak
H
1

You do not have to convert it.

Swift 3.2 is not an actual version. It is how Xcode 9 (and the Swift 4 compiler) calls Swift 3. (I guess to differentiate from Swift 3 built with Xcode 8).

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Compatibility.html

Heathheathberry answered 8/6, 2017 at 12:0 Comment(1)
Yes, but the strange thing is if I build with Xcode 9, it will show me the error of "Module compiled with Swift 3.1 cannot be imported in Swift 4.0"Kobylak
C
0

From Option Menu: Edit -> Convert -> To Current Swift Syntax

Above steps help you to convert into current swift syntax.

Cooler answered 8/6, 2017 at 9:10 Comment(4)
Do you mean do this in XCode9 ?Kobylak
Your code is in swift 3.1 and you want to convert it in 3.2, so open xcode 8.2 and convert it into 3.2 and then open xcode 9 and then convert it into swift 4.0Cooler
Thank you, but I will not convert to swift 4.0 until Xcode 9.0 official edition published.Kobylak
And I use Xcode 8.3.3 to do the convert, but it only shows me that Code already been 3.* and it don't change file. Not work as my expected.Kobylak

© 2022 - 2024 — McMap. All rights reserved.