问题
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?
回答1:
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.
回答2:
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
Here is the article explaining it.
https://medium.com/@mihirpmehta/how-to-modify-cocoapods-library-within-pods-647d2bf7e1cb
来源:https://stackoverflow.com/questions/40948995/proper-way-of-editing-a-cocoapod-library