Proper way of editing a CocoaPod Library

妖精的绣舞 提交于 2019-12-23 18:29:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!