编辑CocoaPod库的正确方法 [英] Proper way of editing a CocoaPod Library

查看:145
本文介绍了编辑CocoaPod库的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装CocoaPod之前,我经历过.

I experienced before that manipulating CocoaPod installed.

假设我通过CocoaPod安装了TheLibrary.swift.现在它在Pods > Libray > TheLibrary.swift下.编辑该文件是非常不好的做法.那么编辑它的正确方法是什么?我想我读到它可以通过extension(?)完成,但是我完全不确定它是如何完成的.

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?

扩展我的问题,如果Pods > Library > Supporting Files中还有其他支持文件,应该采取什么正确的方法?

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

推荐答案

如果要在TheLibrary中编辑代码的行为,则应分叉它,并使用自己的代码,可以根据需要进行编辑.如果您想同时更新发布的新代码,则必须将TheLibrary合并到fork中.

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.

但是,如果要向TheLibrary添加其他内容,则可以继承要更改的类,并对该库使用正式的Pod.您只需将所需的功能添加到您创建的子类中即可.

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.

请注意编辑Pod文件-它会在您的计算机上正常运行,直到您运行pod install或pod update.然后,您将拥有原始代码,而无需进行编辑.另外,可能的团队成员不会进行这些更改,因此请不惜一切代价避免这样做.

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.

这篇关于编辑CocoaPod库的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆