Static / dynamic library in pure swift

is it possible to create swift static or dynamic library or a framework without exposing the source code?

i am thinking of splitting the sources so that protocols are exposed (similar to how .h files are exposed in C / Obj-C) while the rest of the code is compiled (like .c / .m files compiled to .a or dylib or a framework). some bloat will appear as a result of those efforts (e.g. duplicating what was in the class to the protocol, etc). am i on the right track or is there a better approach?

ideally i do not want to involve Obj-C.

You will want to watch this. SwiftPM is adding support for binary dependencies that are xcframework files.

If you want this on non Apple platforms as well you will have a lot more trouble. You have to provide a way to download all the artifacts and people linking have to provide flags the linking flags. I successfully did this at my previous job but no long have access to the things I did there so I can’t tell you the flags or artifacts you will need.

1 Like