Can I wrap an iOS Swift Framework into a static library with C API? - ios

I'm building an iOS app that uses ARKit, which constrains me to use Xcode 9.3, Swift 4.1. Now I have a Swift 4.0.2 framework (3rd-party) which I want to use in this app.
To the best of my knowledge, I can't use Swift 4.0.2 for my project (due to ARKit dependency).
Solutions I've come up with:
The obvious solution would be to get a Swift 4.1 version of the 3rd-party framework. However, I'd have to request that again when Swift 4.2+ comes out, etc.
Request an ObjC library from the 3rd-party.
Building a static Swift library (possible as of Xcode 9 beta 4) from the framework - but this still results in a Swift version dependency.
So I'm trying to build a static library that has a C API (i.e. a stable ABI) as a repackaging/wrapper for this Swift framework and then work with this lib.a.
Is this technically even possible? Has anyone ever done this?
Is there a better solution which I'm missing?

Related

iOS: Binary Framework using Swift

If I make binary framework using swift, will it support objective C projects and what will be minimum supported version? is there any other drawbacks compare to objective c framework?
Yes, Binary frameworks in Swift will support Obj-C projects. Please ensure Obj-C related settings in Build Settings of Framework project are enabled. It will be enabled by default to create bridging header to inter-operate with Obj-C.
Minimum supported OS Version
With Swift ABI stability achieved in Swift 5 and now, module stability in place, there is no need to ship Swift source code while sharing the frameworks. If we want to share the library, Binary framework (xcframework) can be created and shipped without worrying about Swift compiler version incompatibility errors.
Since binary frameworks is dependent on module stability, and in turn, ABI stability, it needs Swift standard library in OS itself. Apple started including Swift standard library in OS when Xcode 10.2 was released, in which Swift 5 was supported. It means, iOS < 12.2 will not have Swift standard library. So, in case of iOS version < 12.2, all swift apps will have their own runtime library included in it. In case of pure Obj-C projects running in iOS < 12.2, ensure "Always Embed Swift Standard Libraries" to Yes in Build settings. Otherwise, it will crash in runtime. So, with respect to OS versions, we see this as the only limitation.
I was able to run a pure Obj-C project using Binary Framework in Swift, even in iOS 9 simulator.
Advantages of using Binary Framework
Binary Framework in swift can be created for all devices, simulators and for all platforms (iOS, MacOS, watchOS, tvOS). It's a single library for all platforms.
We need not ship actual swift source code in framework.It has resolved Swift compiler incompatibility issues.
Interoperability with Obj-C is simple and effortless and can't vouch same on vice-versa.
Hope it helps.

Updating Xcode cause fail in loading frameworks

I have updated my Xcode Client to 10.0 and installed all components. Now i have 9 errors in my project (a Swift project, that needs to be converted to Swift 4.2).
I use Facebook and Vuforia framework, and it seems like the problem lies there. I have tried to update the Pods, but this make no difference.
It is like the frameworks cant be read properly, because they are not converted yet. But i cant convert to Swift 4.2 as long as the build faild. Do i need to update the frameworks somehow?

Convert from Swift 3.0 to Swift 2.3

I have a static library that I converter from old Swift to Swift 2.3 and later to Swift 3.0.
Now I need both version (2.3 and 3.0) of the library, but I forgot to take a backup of version 2.3. And I only have 3.0.
Is there a simple way to convert back from Swift 3.0 to Swift 2.3?
Simple, not really, but this will work.
If you don't have it, download XCode 7.3.1 from Apple
Open your library in the 7.3.1 version and correct whatever errors appear
Migrate the corrected code from step 2 into XCode 8.2 or lower (8.3 will not support Swift 2.3)
As mentioned in the comments, maintaining your code in a version control system will spare you problems like this in the future, and is generally just a good idea.
You don't even need to set up your own system, since git is part of MacOS, and XCode can handle simple git features for you.

Is it possible to use libraries written in an old version of swift in a project with a newer version of swift?

I'm working on a project in Swift 3. However, many libraries are still using Swift 2.3.
Is there a way of making use of them in my project as they are?
Since it's possible to use Objective C libraries in Swift, I figure there's a chance.
Maybe this reference from Apple answers the question:
unfortunately it would seem to be impossible:
First, Swift 2.3 and Swift 3 are not binary compatible so your app's entire code base needs to pick one version of Swift.
https://developer.apple.com/swift/blog/?id=36

Swift Mapbox 3.01 Framework

Trying to get Mapbox framework 3.0.1 working on Swift iOS 9.1 - Followed all the steps here : https://www.mapbox.com/ios-sdk/#binary
When rendering the xcode project, I am getting a weird error when the actual map view is called: Couldn't find resource mapbox.png in bundle.
Anyone any idea?
Sorry for the confusion here. I just updated the docs, but you want to use one of the static library downloads, with the libMapbox.a, not the framework. The framework is used for CocoaPods install and soon, in future, will be a standalone install method.

Resources