Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way of editing a CocoaPod Library

I experienced before that manipulating CocoaPod installed.

Let's assume I have TheLibrary.swift installed via CocoaPod. Now it's under Pods > Libray > TheLibrary.swift. It's very bad practice to edit that file. So what is the proper way of editing it? I think I read that it may be done with extension(?), but I am completely unsure about how it is done.

What should I do if I need to edit just one function from that file, for example?


Extending my question, if there are other Supporting Files in the Pods > Library > Supporting Files, what should be the proper way to take?

like image 798
senty Avatar asked Oct 31 '25 16:10

senty


2 Answers

If you want to edit behaviour of the code in TheLibrary, then you should fork it and use your own code which you can edit as you wish. In case you want to update with new code that is released in the meantime you will have to merge from TheLibrary to your fork.

Doing it this way you will have full control over the code from the library.

However, if you want to add additional stuff to TheLibrary, you can inherit class you want to alter and use official Pod for that library. You will just add the functions you want to the subclass you created.

For the former you can create extension as well for the particular class where you will add your functionality, e.g. function.

One caveat the editing pod file - it will work on your machine until you run pod install or pod update. Then you will have original code without your edits. Also, possible team members won't have these changes, so avoid it at all costs.

like image 162
Miknash Avatar answered Nov 02 '25 08:11

Miknash


In fact there is a third way in which you can modify the library and get future updates from the library, all while still maintaining it via cocoapods

enter image description here

Here is the article explaining it.

https://medium.com/@mihirpmehta/how-to-modify-cocoapods-library-within-pods-647d2bf7e1cb

like image 35
Mihir Mehta Avatar answered Nov 02 '25 07:11

Mihir Mehta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!