Swift framework problems with Xcode compatibility - ios

I have a framework that I distribute to customers without giving them access to the source code, depending on which version of Xcode I use to build it, they get errors like module compiled with Swift 4.1 cannot be imported in Swift 3.2.3 when importing the file .
I couldn't find any setting in the project that allowed me to build backwards compatible version of my framework. Specifically the problem is between 9.2 and 9.3, but at the same time this seems to be a common problem, how can I build the framework so that it works with all the previous versions of Xcode?

Until Swift 5 is released with ABI stability, your library has to be compiled with the same version of Swift as the parent app. This means multiple copies out there based on Swift / Xcode version.
Once Swift 5 is released, then you can compile a copy to be used in any app compiled with Swift 5 or greater.

Related

Swift Module stability: Module compiled with Swift X.Y cannot be imported by the Swift X.Z compiler

Let's start by existing questions,
Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler
Module compiled with Swift 5.1 cannot be imported by the Swift 5.0 compiler
Module compiled with Swift 5.1.2 cannot be imported by the Swift 5.2.4 compiler
And, now with XCode 12(12A7209)
Module compiled with Swift 5.2.4 cannot be imported by the Swift 5.3
compiler
The framework was compiled in the lower version of Swift (Swift 5.2.4). However, it worked perfectly with XCode 12 beta.
Solution tried:
Setting Build Libraries for Distribution to Yes
Shipping Binary Frameworks With Swift 5.0
Whole point is the Swift ABI stability for binary framework and how to achieve it across different swift version.
Please advice. Thank you in advance!
You need Module Stability, not ABI stability.
The difference and the way how to achieve Module Stability, are described here: https://www.donnywals.com/what-is-module-stability-in-swift-and-why-should-you-care/
Here is WWDC session that explains swift binary frameworks (time code: 17:00).
Briefly, your framework
should be built with Build Libraries for Distribution set to Yes
set the Skip Install property to No.
distributed as .xcframework with variants for simulator and device
You'll need to ensure that frameworks embedded into .xcframework all have .swiftinterface file inside of Modules/<name>.swiftmodule folder.

Module compiled with Swift 4.2 cannot be imported by the Swift 5.0.1 compiler [duplicate]

This question already has answers here:
Module compiled with Swift 4.0 cannot be imported in Swift 4.0.1
(8 answers)
Module compiled with Swift 4.2.1 cannot be imported by the Swift 5.0 compiler
(8 answers)
Closed 3 years ago.
My project is working on Xcode 10.1, but when I am trying to work with Xcode 10.2.1, I got this issues:
"Module compiled with Swift 4.2 cannot be imported by the Swift 5.0.1 compiler: /xxx/xxx/xxx/xxx/xxx/xxx/xxx.framework/Modules/xxx.swiftmodule/i386.swiftmodule"
"Module compiled with Swift 4.2 cannot be imported by the Swift 5.0.1 compiler: /xxx/xxx/xxx/xxx/xxx/xxx/xxx.framework/Modules/xxx.swiftmodule/x86_64.swiftmodule"
I am getting this issues about embedded framework that I am using. When I checked the same issues, I didn't find any solutions on internet. Do you guys have any idea?
Thanks.
You have to recompile all of your dependencies with the same version of the compiler by Clean All -> Build.
Also make sure that Locations -> Command Line Tools is set to the latest Xcode 10.2.1 if you have both versions installed side-by-side.
I understand this is an external module/framework.
If you don’t have access to the source files then you need to request the vendor to update the framework, i.e., compile it with Swift 5.
If that is not possible then you need to keep your project on Swift 4.2 until further...
Cheers!
Change your Swift Language Version from build setting.
Go to YourTarget > Build Settings > Swift Language Version for all of your Xcode targets.
Hope this will work.

RealmSwift: Module Compiled with Swift 3.0 cannot be imported with Swift 3.0.2

I am trying to use RealmSwift with my Xcode project. I have used it several times before, but since the last Xcode (8.2) update I keep getting the same error "Module compiled with Swift 3.0 cannot be imported in Swift 3.0.2".
I have tried installing it through cocoapods and I have tried installing it directly. I have tried changing the IOS. I have updated the pods and downloaded the latest version, but nothing is working.
I looked at similar issues posted on here with no luck:
Realm's Swift module compiled with Swift 3.0 cannot be imported in Swift 3.0.1
Module compiled with Swift 3.0 cannot be imported in Swift 2.3
Migrating from Swift 2.3 to Swift 3 with dependencies
Any advice would be appreciated.
You can download the Swift 3.0.0 toolchain as a temporary workaround until the 3rd party framework has been updated to the latest version. Swift 3.0.0 is available here:
https://swift.org/download/
After downloading it, you can choose to use Swift 3.0.0 from the menubar:
Thought this might help anyone facing the same with other 3rd party frameworks that haven't yet been updated.
Add Realm.framework in Build Phases by using + -> New Copy File Phase. Follow the image below.
And import 'Realm/Realm.h" in ProjectName-Bridging-Header.h file.
Swift binaries aren't compatible across different versions. Swift 3.0 and Swift 3.0.2. although virtually identical are still different binaries.
We try to push out new builds of Realm Swift to support new versions of Xcode as soon as possible. At the time of writing, we're now shipping 3.0.2 binaries of Realm Swift.
So as long as you've updated to the latest version of Realm Swift, this shouldn't be a problem anymore: https://realm.io/docs/swift/latest/#getting-started

How do I keep using Swift 2.3, instead of 3.0, Xcode updated and can't build anymore

I am developing an app with 20+ framework dependencies and not all of them are on 3.0 yet. So I want to keep using Swift 2.3. However, after updating my Xcode to 8.0, I can no longer build my app. It fails with the following error:
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.
I don't want to convert the whole project to 3.0 yet.
So my question is how do I keep everything same after Xcode 8.0 update?
In case you want to use Swift 2.3 you should go to Build Settings -> Use Legacy Swift Language Version -> YES this will help you to achieve it. after building the app, there will be minor syntax issues. After fixing (not so hard) it will go as usual
You might want to read this article: https://swift.org/migration-guide/ or more specifically section Using Carthage/CocoaPods Projects.
I guess you could choose Include the source code of the project in your Xcode workspace approach. This essentially means that you keep all your code in Swift 2.3 and make a snapshot of all or some external Frameworks referenced as Pods that are not Swift 3.0 ready.

Realm: Module was created by an older version of compiler and could not build objective-c module

I have followed the steps provided to add the framewowrk from this link https://realm.io/docs/swift/latest/
It gives this error what could be the issue?
Is it because it is compiled with an older version of xcode, since I have the latest xcode 7 beta?
If so, how would I solve this?
You'll have to wait for us to support Swift 2.0 (#2062) before you can use Realm Swift in your Swift 2.0 project.
Because the framework written in Swift which was built in the old version compiler is not able to use in Xcode 7. Therefore, it will be needed to re-build using the compiler of Xcode 7. However, Swift 2 is required on Xcode 7; we are working to adapt RealmSwift.framework to the Swift 2.
I got Realm to work with Swift 2 by doing the following (this is from memory)
Checkout Swift-2.0 branch https://github.com/realm/realm-cocoa/tree/swift-2.0
Build by running /build.sh ios-swift
Copy Realm.framework and RealmSwift.framework into project
Use let realm = try! Realm() as my initializer in place of let realm = Realm()
I use Carthage for all my frameworks, so to keep things uniform I copied the RealmSwift and Realm frameworks into the carthage/build/ios directory and the /usr/local/bin/carthage copy-frameworks build script picks them up
This just randomly started happening to me as well for some reason. Manually compiling the swift-2.0 branch didn't end up working at all.
I ended up converting my entire project to Swift 2.1, and using the pre compiled frameworks. Now I'm up and running.
FWIW - The conversion to 2.1 from 2.0 wasn't nearly as painful as any of the other conversions from 1.0, or 1.2.

Resources