xcode 从 CocoaPods 框架编辑锁定的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34915886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:27:00  来源:igfitidea点击:

Editing locked files from a CocoaPods framework

iosxcodedependenciescocoapods

提问by 17nisa

I have an Xcode workspace that uses CocoaPods to include several third-party frameworks. I would like to edit a line of source code within one of these dependencies. However, when I do so, Xcode warns me that the file is locked and that any changes I make may not be saved. So my question is: will my changes to the source code be discarded when I run a pod install/update? If not, is there any other scenario, possibly unrelated to CocoaPods, that would discard my changes? And finally, is there any good way that I can edit the source code without running into such problems?

我有一个 Xcode 工作区,它使用 CocoaPods 来包含多个第三方框架。我想在这些依赖项之一中编辑一行源代码。但是,当我这样做时,Xcode 会警告我该文件已被锁定并且我所做的任何更改可能无法保存。所以我的问题是:当我运行 pod install/update 时,我对源代码的更改会被丢弃吗?如果没有,是否还有其他可能与 CocoaPods 无关的场景会丢弃我的更改?最后,有没有什么好方法可以让我编辑源代码而不会遇到此类问题?

Thanks in advance.

提前致谢。

回答by technerd

You can not make changes in Original Pod file. If you want to add some more features then you have to fork that particular repo.

您不能在原始 Pod 文件中进行更改。如果您想添加更多功能,则必须分叉该特定存储库。

Follow steps to do so :

请按照以下步骤操作:

  1. Find library you want to use on Git.
  2. Fork library.
  3. Update Podfile which refer to your forked version. Suppose I want to fork GPUImage Library. Then point your fork in Podfile as given.
  1. 找到你想在 Git 上使用的库。
  2. 叉库。
  3. 更新 Podfile 指的是你的分叉版本。假设我想分叉 GPUImage 库。然后按照给定的方式将您的 fork 指向 Podfile 中。

pod 'GPUImage', :git => 'https://github.com/UserName/GPUImage.git'

pod 'GPUImage', :git => ' https://github.com/UserName/GPUImage.git'

  1. Make your changes.
  2. Commit/push your changes to your forked repo.
  3. Submit a pull request to the original author of Library.
  4. If pull request is accepted and the pod is updated, revert back your Podfile to use the public pod.
  1. 进行更改。
  2. 将您的更改提交/推送到您的分叉存储库。
  3. 向 Library 的原作者提交拉取请求。
  4. 如果 pull request 被接受并且 pod 被更新,恢复你的 Podfile 以使用公共 pod。

You can create Category (Objective C) or Extension (Swift) to extend or add some features to existing class.

您可以创建 Category (Objective C) 或 Extension (Swift) 来扩展或添加一些功能到现有类。

回答by Jules

You can do this simple. Just modify the pods src code. Switch to another brach and switch back. Xcode would rebuild pods with your modified code. If you want go back, you should remove the pod in Podfile, execute pod install.Then add pod back, execute pod install. This solution is just for debug. For permament, you should take @technerd's answer

你可以简单地做到这一点。只需修改 pods src 代码。切换到另一个分支并切换回来。Xcode 将使用您修改后的代码重建 pod。如果你想回去,你应该删除Podfile中的pod,执行pod install。然后重新添加pod,执行pod install。此解决方案仅用于调试。对于永久,您应该接受@technerd的回答

回答by Mihir Mehta

In fact there is another way in which you can modify the library as per your custom needs and get future updates from the library, all while still maintaining it via cocoapods

事实上,还有另一种方法可以根据您的自定义需求修改库并从库中获取未来的更新,同时仍然通过 cocoapods 维护它

enter image description here

在此处输入图片说明

I have written article/tutorial explaining the same.

我写了文章/教程来解释相同的内容。

https://medium.com/@mihirpmehta/how-to-modify-cocoapods-library-within-pods-647d2bf7e1cb

https://medium.com/@mihirpmehta/how-to-modify-cocoapods-library-within-pods-647d2bf7e1cb