Manually installing pod files - ios

I'm trying to work with a git repo who's dependencies are configured through CocoaPods. However, my internet connection is rubbish (I'm on holidays) and keeps cutting and interrupting pod install. I managed to install 2 of the 6 dependencies through pod (took all day) and realised I actually have the zips of these frameworks already on my computer. So I added for example LayerKit to my pods directory in the project folder. Then when I run pod install again, it hasn't noticed that I already added the file... Any idea how I can fix this or a better way I can work around this. I really have no idea how pod works, I usually just run pod install and it all works miraculously.

You probably want to create a folder under your project's main folder and place all of them in there.
Once that is done, update your target in your Podfile to look like this:
pod 'NameOfPod', :path => 'Relative/Path/To/Podspec'
That allows you to access the pods locally on your system. The path needs to point to the Podspec file for the pod. Also, make sure you do not alter the directory structure in the pods, as this will likely break them.

Related

cocoapods - edit development pod's source file

I have a question regarding cocoapods' development pod.
I find a source file in 'development pod' which contains a bug that I need to fix.
I know how to change the codes to fix it, but I am not quite sure how to fix/patch the file itself so that when I redo pod install later, it sustains the changes I made.
After some research, I figured out that I can fix/patch pod file by using https://github.com/jpsim/pod-diffs/blob/master/README.md
However, the file I like to fix resides in Development Pods.
According to https://guides.cocoapods.org/making/using-pod-lib-create,
Development Pods are different from normal CocoaPods in that they are
symlinked files, so making edits to them will change the original
files, so you can work on your library from inside Xcode.
Does this mean I can safely make modifications in the file itself to fix the bug?
Sorry, I am not familiar with fixing Pod files. Any help will be appreciated.
Yes, this would work. When using a development pod, running pod install will not overwrite your changes with whatever is in the pod's repo, but instead will use the code as specified in the :path of your development pod.
When you do this, you should a) put the development pod under your own version control (usually in a fork of the original pod), and b) consider offering your fixes upstream via a pull request.

How do I create a cocoapod framework and add files to it?

I'm creating a private pod and would like it to be used as a module. According to Using Pod Lib Create, in CocoaPods.org:
The first question you're asked is what language you want to build a pod in. For both choices CocoaPods will set up your library as a framework.
In fact, when I run pod lib create MyLibrary, the initial project template they generate does have everything configured to be a framework, so that I can add a class to Development Pods/MyLibrary, and access methods of that class from the sample project simply by importing the module using #import MyLibrary; (or import MyLibrary, in Swift).
The problem lies on the fact that the same page tells us
With the questions over, we run pod install on the newly created Project.
And as soon as I do that, the module-related files are gone, and all the files that I had added to my Development Pods folders are gone. Not only that, the framework Target itself is gone, so it's not even a matter of simply adding the files back again.
What's the correct approach here? I don't seem to find anyone with the same problem.
I'm running Cocoapod v1.5.3
Any help is highly appreciated!
tl;dr:
pod lib create MyLibrary
cd MyLibrary/Example
pod install
Now notice that the project has no module configuration anymore. How can I avoid this?
According to the same page:
[!] Note: Due to a Development Pods implementation detail, when you
add new/existing files to Pod/Classes or Pod/Assets or update your
podspec, you should run pod install or pod update.
In my experience, you have to be very careful when adding new files because they may end up on a different folder than the expected Pods/Classes.
When in doubt, I go to the folder containing the project and search for the missing file and move it to the correct folder.
What's super important is that when you run pod install CocoaPods will look into your PodSpec and only install files that match the source_files criteria mentioned in the PodSpec i.e. the files need to be
correct extension
correct path.
But basically you have to add the file to the exact directory you want. If you're using groups it gets messed up. So instead of adding a new file using Xcode, just add the new file using Finder and then run pod install.
Not sure why but if I add to the same group that has a similar file at the appropriate directory, Xcode and CocoaPods will just put the file at the top directory.
On a complete tangent:
If you've been pointing locally to to your private pod using :path and then add new files into your private pod, those new files aren't reflect in the repo that pull in the private pod. They'r not reflected because their source control is from another git repo.
As long as you see the new file of your private pod in your main app and your main app compiles then you're good.

Pod Install throwing error in terminal for Xcode project

I am trying to install cocoa pods into my project, so followed installation of pod file setup. So, latest pods installed to my system.
When I tried to install pod file to my project throwing following error.
But, pod file create with blank.
I have given following command and getting following error :
MacBook-Pro:Videos username$ pod install
Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client projects
[!] Could not automatically select an Xcode workspace. Specify one in your Podfile like so:
workspace 'path/to/Workspace.xcworkspace'
And I tried Pod init also, if I try to open pod file, its showing empty pod file. And not even showing Target which is default pod file setup.
Anyone suggest me, how to fix this.
This is the general approach while installing pod. Make sure you follow these and it should work fine (I am assuming cocoa pods are installed on your system) So your issue lies in one of the following steps:
Go to the project root directory - cd root_directory_path
pod init
Open pod file and add required pods (See library installation guide. Each has one)
pod install
Empty pod does not get created usually. But even if it does, you can just copy the format of pod file contents into your file and install the pod.
As to your empty pod file, reinstall cocoa pods on your system. Also make sure pod is uninstalled from project/workspace you are working on. There might be a faulty installation earlier.

Xcode cannot see the file added manually into cocoapod

I maintain my 3rd party libs with cocoapods. But recently I found some bugs and would like to add some new features to one of the libs so I manually created some .h and .m files in one of the libs.
However when importing those added .h files, Xcode gave the file not found error and couldn't compile them.
How can I solve the problem?
Thanks.
When integrating the Pods into your project, CocoaPods generates libraries that cannot be easily modified from Xcode. If you're having CocoaPods build frameworks, instead, those cannot be modified at all. You usually have to rerun pod install or pod update to let CocoaPods regenerate them if you add files to a Pod.
If you want to reliably add files to a Pod, you should checkout a copy on your machine, somewhere NOT in you project's folder and use something like the following to tell CocoaPods that that one Pod is one you're developing and therefore should integrate differently:
pod MyPod, :path => 'path/to/MyPod.podspec'
Still, even in this case, if you add files to the Pod, although it's easier to add them from Xcode, you might want to rerun the pod command line tool to have CocoaPods reintegrate your pod. However, in this case, you'll only have to make sure your files are added to the right project target in order to add files directly from Xcode.

How do I use CocoaPods correctly

I have some doubt on CocoaPods
I think the 1st rule is that keep Podfile and ignore pods folder entirely. But I am so confused about this after I have used some time
Since I insist on #1, somebody says *.lock should be kept in repo. Do I need do this?
Pods generates some xconfig files, it seem I can't add HEADER_SEARCH_PATH in it ?
if YES, it breaks my rule #1 again. Please see this question the-target-overrides-the-other-ldflags-build-setting-defined-in-pods-pods
some buddies modify codes managed by CocoaPods such as AFNetworking rather than from custom repo. I told him NEVER do this because it will recover to origin version after pod update/install but after pod update/install his code didn't change. that's WHY?
My opinion is DON'T MODIFY EVERTHING IN PODS PROJECT EXCEPT PODFILE
You should always check in your Podfile and Podfile.lock.
Checking in your Pods directory is debatable. If you would like to be able to clone the project and run it without requiring users to have CocoaPods you should check this in. I personally do not check this directory in, instead you just have to run pod install after cloning the project for the first time.
If you want to alter the xcconfig files with changes such as HEADER_SEARCH_PATH you should check this in so those settings don't get overwritten unintentionally. Really the podspec should handle all of these settings so you probably shouldn't be changing much in there.
If you're planning on altering the code included by a Pod you should either check in your Pods folder or fork the repo and redirect it to in your Podfile. Documentation on that here. This way you can specify that CocoaPods uses the given spec but uses your fork instead.
EDIT The Podfile.lock (similar to the Gemfile.lock) stores information on the actual version included during the install. Consider this:
You require a spec like pod 'foo', '~> 1.0.0 in your Podfile.
You run pod install and it installs the newest version of foo matching the semantic versioning conventions (specified by ~>)
You don't check in your Podfile.lock
Another developer clones the repo, the newest version of foo is now 1.0.3.
They run pod install. Version 1.0.3 is installed even though they didn't run pod update.
This information is 'locked' in the Podfile.lock so that to do this you have to run pod update which should be very intentional.

Resources