How can I compile Swift 2.3 Code in Xcode 8 - ios

I have many issues with my project Swift 2.2 in Xcode8, the pod library generates many error, I did an update of cocoapods and library but I still have those errors, I have convert syntax to Swift 2.3 but the errors are still there. I do not want to convert swift 3 for the time being.
Here is a picture of errors :
Socket Io Client Swift errors
Thank you in advance and sorry for English errors.

Okay, so the problem is that the library you are using is Swift 3. So there is no point saying "I do not want to convert to Swift 3". You have converted to Swift 3 whether you like it or not. You do not need to compile this code as Swift 2.3. You need to compile it as Swift 3.

To run Swift 2.3 in Xcode8, set Use Legacy Swift Language Version to YES within your projects, your targets and your pod framework targets Build Settings.

Related

Can I downgrade swift version to moderate error 'Module compiled with Swift x.x cannot be imported by the Swift x.x compiler'?

I recently started my very first swift experience and I got an error
'Module compiled with Swift 4.2.1 cannot be imported by the Swift 5.0
compiler'
I thought that I can moderate this error just selecting my swift language version on build settings. but it doesn't work.
After few searching, I found that there are two options
Downgrade Xcode
Update modules or Rebuild modules using swift 5.0
Are they only options I got? I don't know why changing swift language version does not do anything.
The swift 5 compiler which is bundled with Xcode 10.2 can compile in swift 4 mode. However, it is still the swift 5 compiler and not the swift 4 compiler that came in Xcode 10.1. Modules built with the swift 4 compiler can’t be imported by the swift 5 compiler.
Therefore, the two options you listed are the only options you have.

Using Swift 3 in Xcode 10.2 - Command /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc failed with exit code 1

My goal is to get the new Xcode 10.2 compile and run our projects that are build using Swift 3 and 4.2 (some cocoapods too) and since Xcode 10.2 comes with Swift 5, an unsupported swift error came up when trying to run the projects out of the box (this is expected):
The solution here is to use an older toolchain as stated on blogs like this, which i did.
All good so far. However, after installing the Swift 3 toolchain from Swift.org, compiling the project will bring the following error:
Command
/Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc
failed with exit code 1
I already deleted Derived Data folder, cleanup pods (my podfile) and reinstalled them, restarted Xcode and Mac multiple times.
Running xcrun -f swift and swift --version will indeed print the correct swift 3.0 toolchain
Yes, I know I could just stay with Xcode 10.1 and don't have these issues. Code migration to Swift 4 is also an option but we don't have the time at hand for now so I'm trying to workout this walkaround.
Please help me to resolve this issue, I'm completely stuck. Thanks in advance.
Xcode10.2 Release Notes
Swift 5 no longer supports the Swift 3 Package.swift tools-version.
Packages still on the Swift 3 Package.swift tools-version should
update to a newer tools-version. (41974124)
Swift 5.0
Source Compatibility As with Swift 4.2, the vast majority of sources
that built with the Swift 4.2 compiler should compile with the Swift
5.0 compiler.
However, the Swift 3 compatibility mode will not be supported in the
Swift 5 compiler. Swift 4.2 is the last release of Swift to support
Swift 3 mode. There are important changes to both the surface of the
language and the interior of its implementation in the releases
following Swift 3 that will be the basis of future (and lasting)
source and binary stability.
Using Swift 4.2.1 toolchain work for me.
But https://swift.org/download/#using-downloads tips:
To submit to the App Store you must build your app using the version of Swift that comes included within Xcode.
Upload to apple connect probably reject by apple.

Convert to Current Swift Syntax Failed - "No such module" (Swift 4, Xcode 9)

In Xcode 9, I am trying to do the automatic conversion to Swift 4.
It fails with the following message:
Convert to Current Swift Syntax Failed
Please ensure that all selected targets build successfully with the currently configured Swift version before attempting a migration.
It's complaining of a missing module. But when I do a regular build there are no issues. Not sure if this is relevant, but the module (which Xcode is complaining is missing) was already converted to Swift 4 earlier (in it's own project).
Note: No Cocoapods / Carthage used here.
Note: Two solutions tried (and worked) but do not address the underlying issue.
One solution is to do the conversion manually (change Swift version to 4 in build setting and apply Fix-Its one by one until no more build errors).
Another solution is to disable the third party framework (comment out all code where it's used), do the auto-migration, and then re-enable the framework. This could get pretty difficult with bigger projects.
I can't find any solution yet.
For now I fix manually setting Swift Language Version
After changing from 3.2 to 4.0 I compile and fix errors and warnings manually.
I'm waiting for a better solution!
I also got this problem while converting my project to Swift 4.0. Looks like problem appears when you try to convert target which imports a framework which is already in Swift 4.0. At your screenshot you try to convert 'RecipeTextParser' which imports 'SovaTools' which is already Swift 4.0.
I found dirty, but working solution. You can use older(Swift 3.2) version of 'SovaTools' when converting. You should NOT check it's mark in target selection window of conversion tool. Then, when 'RecipeTextParser' will be successfully converted you can use Swift 4.0 'SovaTools' version again.
I got this error and in my case one of my Pods(the one Xcode was complaining about) was a Swift 4 target and the rest were Swift 3.2. Looking at the build logs it looks like Xcode built that framework in one location and was searching for it in another. When I reverted that Pod to an older version(that used Swift3.2) the problem went away. Obviously a Xcode bug. HTH
Just update your pod and it will resolve the issue.
To update pod:
open terminal and go to your project directory
type pod update
This resolved my issue.
Xcode (Xcode 9) language migration feature is not as much accurate that it can migrate your complete code/project from one swift version to another with zero tolerance. It skips few code migration for us (developers). It may be bug or inaccuracy of tool. But you need to put some manual effort also, to completely migrate swift language version for your project/code.
Now, according to your snapshot, Xcode is showing and error for 'RecipeTextParser' framework. I think this is an external/third party framework. Another point to note, you've integrated this framework using CocoaPods:
Any one of following can be reason for failure of code migration:
CocoaPods locks framework (files) for editing. So language migration process may not be able to migrate (or identify) code for external/thirdparty framework.
In general terms, Framework is package of code files, so framework itself may not allow file/source code editing.
Suggestion as solution:
Update your cocoa pods as well as all frameworks integrated using cocoa pods compatible to latest swift language version.
If you've manually integrated/added external/third party frameworks, then you need to update/replace those also.
Some manual effort is required to completely migrate code between swift languages. I tried swift migration with above options and my all projects are now compatible with swift 4.

How do I run Backendless with Swift 3?

I cannot get Backendless to compile in Xcode 8 with iOS 10 and Swift 3. I have updated to the latest version of Backendless-iOS-SDK via CocoaPods. Every time I try to compile, I am met with numerous errors in the parts of my code that access the Backendless SDK. Every time I fix the errors, countless more appear when I try to run. This makes me think I have done something wrong during the process of upgrading the SDK.
Any ideas what could be happening here? Is it expected that all my code that accesses Backendless needs to be changed when upgrading to Swift 3? (Please note that I have ALREADY Converted to the latest Swift 3 syntax).
Is the Backendless SDK now compatible with Xcode 8 and Swift 3?
Any ideas what could be happening here? Is it expected that all my code that accesses Backendless needs to be changed when upgrading to Swift 3? (Please note that I have ALREADY Converted to the latest Swift 3 syntax).
Yes, you might need to change the code if its not converted by the migrator.
Is the Backendless SDK now compatible with Xcode 8 and Swift 3?
Yes, because the Backendless SDK is in Objective C so there will be no issues using it.
There is issue on swift3 installation via cocoa pod as of the moment.. please use option 2 in the documentation... importing the lib adding it manually is better.

How can I use swift 2 and swift 3 at the same time?

Although swift 3 is released, I don't want to update my code just yet, because a lot of the CocoaPods I used are still in swift 2. I don't know what the migrator will do to those pods. Will they remain unchanged, causing the project to not build successfully? Or will they be migrated to Swift 3 as well? I don't know!
On the other hand, I really want to try out the new syntax and other new features in Swift 3. They seem really cool!
How can I continue developing my existing projects with Swift 2, but for other projects, compile with Swift 3?
In other words, how can I choose a compiler for a project?
How can I continue developing my existing projects with Swift 2, but for other projects, compile with Swift 3?
Install both Xcode 7 (which has Swift 2) and Xcode 8 (for Swift 3) and use the xcode-select command line tool to switch between them.

Resources