31

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?

Thanks in advance.

17nisa
  • 315
  • 1
  • 3
  • 5
  • You can fork the third-party framework on GitHub that you want to edit source code. And then edit source code with your idea. After that you can create your own podspec file to add your repository to CocoaPods library. – SeraZheng Jan 21 '16 at 05:21
  • Try making changes to the source within the pod after you unlock for editing. Then, clean the Xcode project, which will make recompiling the pod changes necessary, build/run, and it should work. The only downside is with pod upgrades or installs, it may remove your changes, so backup your changes if possible. – Chris Oct 02 '18 at 22:21

3 Answers3

39

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.

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.

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.

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

technerd
  • 14,144
  • 10
  • 61
  • 92
  • I forked the library, updated the podfile, and ran 'pod install'. When I go to make changes it still says the source code is locked and that I don't have write permissions. Is it ok if I unlock it since it's forked, or is it not supposed to be locked in the first place? – 17nisa Jan 21 '16 at 18:50
  • Now you can unlock it. – technerd Jan 22 '16 at 03:42
  • thanks to this comment I made my first ever contribution to an open source project :D For some reason I thought it was way more complicated :) – budiDino Jul 12 '19 at 14:45
3

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

Jules
  • 631
  • 6
  • 14
0

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

enter image description here

I have written article/tutorial explaining the same.

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

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