Search code examples
swiftxcodecocoapodspodfile

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?


Solution

  • 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.