Pick [static|dynamic|.xcframework] ?

Photo by Daniel on Unsplash

Pick [static|dynamic|.xcframework] ?

Someone asked me that question earlier. Well, as with everything else, it depends.

First, if your module/library will need to be distributed with assets, you should go with a .xcframework as it can include additional files. Manually distributing a .a or .dyld file along with a set of assets to include is a recipe for disaster. So you'll pick .xcframework; and in that framework will be your static and/or dynamic library.

As for static vs dynamic, it depends on how your app will be using it. If it will always be loaded and your app requires that functionality to work, then build it as a static library. Your main app executable will be slightly larger but still smaller than app binary + dynamic library. And since you will always need to load the dynamic library, you will also save some time because it will already be linked at compile time. So... faster for your users.

However, if your library contains a bunch of stuff that's mostly needed only for specific edge cases in your app, then you will want to pick a dynamic library. This will allow your app to start immediately, and iOS will load the dynamic library as needed at runtime.

Note that using a dynamic library may also introduce some unexpected delays due to the dynamic nature of the linking. So be careful about making use of a function from a dynamic library for the first time during animations.