Implementing Swift Infrastructure Framework

Our company wants to distribute a closed source SDK for iOS to our customers. I used Cocoapods to create a framework and created an example application using it. Previously, the application worked perfectly on the simulator, as well as when deployed to the device. However, I also inserted the Pods.framework file in the application itself. Another piece of information that may be of interest is that the structure is written in Swift, the cocoapods dependencies included are Swift and Objective-C.

I wanted to simplify the management of container requirements, so the user did not need to bother them and try to insert the Pods.framework file inside the created SDK - so I removed the steps on the Embed Pods Frameworks and Copy the resource resources from the sample application, leaving them only within the framework, I also deleted Pods.framework as a dependency of the sample application, leaving it only in the SDK. This seems to work in the simulator, but the application is now crashing on the mobile device with a dyld: Library not loaded error.

Having studied this, I came across several related discussions: https://github.com/CocoaPods/CocoaPods/issues/344 https://objectpartners.com/2014/06/25/developing-private-in-house-libraries-with -cocoapods /

However, the proposed solution for using private containers does not seem to work for us, I understand that the source code in the private package will still be open, and we will not be able to share it with our customers.

Can someone advise a solution that will work in this case?

+6
source share
1 answer

Well, I finally have a longer-term solution. This is a modified, cleaner version of my old one, now that I understand how best to use Xcode in my Swift subforums

The problem that makes the distribution / compilation a bit ugly:

Since the standard Swift libraries are not integrated on a device such as Obj-C, and they do not guarantee stability between versions (stable binary interface promised in Swift 3: https://github.com/apple/swift-evolution#development-major -version - swift-30 ), we need to make sure that the whole project is compiled against the same version of Swift. This means that the guy using your closed source infrastructure must use the same version of Swift in his Xcode for his project as for compiling the library, even if he doesn't use Swift in his code, because ultimately it is his the Swift version that gets into the application and your SDK works against. This is only a problem for closed source frameworks, because open-source will always be compiled against the same version as the final project. A possible workaround is to restrict clients to the same version that you are using, or distribute multiple compilations (e.g. Swift 2.1 and Swift 2.0). To fix this, you can provide users with copies of binaries compiled in several versions of Swift.

Also, here is what I had to do during compilation / distribution in order to create a binary structure that works in Swift:

When creating a frame:

  • In the target program, be sure to add Pods.framework to the Linked structures and libraries (make sure that this is a pre-compiled RED version of Pods.framework, I had a blacklisted Pods.framework in the same directory, which was built perfectly, but then brought to create a structure that could provoke the project to lack of armv7 architecture during the linker phase in a later project).
  • In the build settings in the Custom section, add a field named BITCODE_GENERATION_MODE and set it to the bitcode
  • DO NOT #import any frameworks in your bridge header, all instructions indicating that you do this remain with Swift 1.0-1.2 days, you no longer need it, and this does more harm than good (a later project will complain that he cannot find these headings that are not even subject to him).
  • Change build target to universal iOS device, Archive and Export framework

When creating a project using the framework:

  • Drag and drop the framework into the project, on the General tab, add it to the Embedded binary files and Related structures and libraries (you only need to add a frame, not sub-frameworks or a pods file)
  • In the "Build Options" tab, add a new path to the platform Search Path : $ (PROJECT_DIR) /MyFramework.framework/Frameworks
  • Build a project
+1
source

All Articles