How to add resources (xib, etc) to Static Library (iOS/Swift/Objc)

If you need to ship your static library that uses resources (images, xibs, fonts, etc) then you need to bundle them additionally. This article will guide you through that process.

  1. Select your Static Lib project and click create a New Target

2. Navigate to MacOS tab and choose Bundle, then finish the creation.

3. Once the target is created, select it from the left-hand side menu, navigate to Build Settings, search for Supported Platforms and choose iOS

4. In the same place, search for Base SDK and choose iOS

5. Then navigate to your Static Library target and inside Build Phases tab add Static Lib Resources bundle that you just created to Dependencies

6. After that, navigate to your App Target that includes your Static Lib. Navigate to Build Phases of your app and add your Static Lib Resources bundle to Copy Bundle Resources

7. Now you could safely add any .xib, assets, or any other file to your Static Lib Resources bundle that you want to have access to in your Static Lib.

Well done! Setup is completed, now we need to correctly ask for resources in code.

For that, please, refer to this code snippet that shows how to load a xib and an image from the resource bundle inside the static library.

Note: replace “StaticLibResources” with the name of your Static Lib Resources bundle

The whole project is available on GitHub: Link

If you encounter any error, feel free to contact me on Twitter and I’ll try to help you!

Also, feel free to follow if you want to stay up to date with new articles like this!

iOS & Android developer in FinTech