How to create, use your own cocoapods library

Kaan Vural
Mac O’Clock
Published in
3 min readSep 17, 2021

We mostly use cocoapods to add 3rd party applications to our project. To create a modular project based on Cocoapods, each feature corresponds to a new library and we need to add it like a 3rd party application in our main project. As a person who has not used this structure before, I will summarize the basic implementation order by considering the problems I have encountered.

Firstly, we need to create a Cocoapods library.

Terminal -> pod lib create [add your library name without brackets]

After completion of these questions, Xcode will automatically open created library. It’s highly recommended to create a library with an example project. Otherwise, you may install your pod library to any project by locating it in podfile.

In order to use assets(images, localization, xib etc.) in your pod library, we need to create a bundle with below + button by selecting Bundle under the macOS group ;

If we are going to use that bundle in iOS project, we should change the Base SDK to iOS under the Build Settings after selecting the bundle target.

Our pod target must include the Bundle as Copy Bundle Resources. (Use + button to add)

And any asset that will be created in the future must have the same relation with the Bundle as below.

Please be informed that, any file you have created will be automatically added as Copy Bundle Resources. If not so, please try to update your pod (by using “pod update” in Terminal). Any asset file created must have the target membership of the Bundle.

As you need to update all other information in your podspec file, you must have the right file path for the assets as the below.

To use your assets in your pod library, you have to ensure that you are giving the right path for the Bundle. (You may use the gist attached)

Last but not least, in order to use any other 3rd party library in your pod library (the one you have created) you should include them into your podspec file as s.dependency. (for the detail of s.static_framework, you may check the link attached.)

  • Please don’t forget to update your pods of the main project every time you have encountered a dependency problem.

--

--