4

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?

senty
  • 12,385
  • 28
  • 130
  • 260

3 Answers3

3

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.

Miknash
  • 7,888
  • 3
  • 34
  • 46
3

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

Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
0

The above solutions are good, but I am sharing one alternate solution.

As written in question, If you want to alter the code which is pod library:

step 1: Clone the pod lib repo to your system

step 2: Check the source file is accessible?

step 3: If yes, you can copy those file under you bundle in one folder

step 4: And.. , now those lib source files are part of your project bundle you can modify it as per your requirement

Note: In this solution you may face problem of getting updated changes from pod libs

Harsh Pipaliya
  • 2,260
  • 1
  • 14
  • 30