how to add only swift static lib's binary executable to swift app, in Xcode?

Viewed 226

I need to send a swift lib executable to consultants and don't want to reveal source code.

Consultants have their own iOS GUI app, which needs to call my BLE lib.

In C, I'd send only the lib's .a and .h files. How do I do this in swift?

To clarify, this is for distribution within our finite development team, and NOT for public distribution nor Apple Store.

UPDATE...
I followed answer of Eugene D...
I created new Xcode project: kingpin_mobile_framework_12Nov21a and set its Mach-O=static lib and its BUILD_LIB..=Yes

Then I went to my app project and clicked and dragged project kingpin_mobile_framework_12Nov21a
into app project and build.

But now app project can't import the swift in the new framework:
import kingpin_mobile_framework_12Nov21a
gets build error "No such module":

1 Answers

You can compile a Swift static framework - it's the same as static library, but also has .swiftmodule inside of the framework bundle.

Create a framework target in your project, add your swift files to it, then change MACH_O_TYPE build setting to "Static Library", and set BUILD_LIBRARY_FOR_DISTRIBUTION to "Yes".

You can also compile static frameworks for different architectures and then create a static xcframework out of all of them. This will ensure that consultants can run your framework on simulators, devices and even mac catalyst (if you support it).

Make sure to inspect .swiftinterface after the framework is compiled, in order to ensure that there is nothing exposed in it that should not be there (i.e. some types or methods that were intended to be private).

Beware that static frameworks can not carry any resources inside - only their binary will be used during linking.

Related