Currently I'm working with 2 workspaces: First workspace contains MyLibrary pod, created by the pod lib create MyLibrary command. The second workspace I'm using is my project's workspace which includes the project I'm working on.
Is it possible to integrate MyLibrary workspace inside the second workspace? It will be very helpful as I could see all my code in a single workspace.
Found documentation on this:
Using the files from a local path.
If you wold like to use develop a Pod in tandem with its client project you can use the path option.
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
Using this option CocoaPods will assume the given folder to be the root of the Pod and will link the files directly from there in the Pods project. This means that your edits will persist to CocoaPods installations.
The referenced folder can be a checkout of your your favorite SCM or even a git submodule of the current repo.
Note that the podspec of the Pod file is expected to be in the folder. (http://guides.cocoapods.org/syntax/podfile.html#pod:)
Another important note:
This is awesome for small changes that are made exclusively on existing source files. Adding or removing source files is out of the question because you have no access to the project file. For bigger changes like that, you should open the local project file. (http://www.cocoanetics.com/2014/07/development-pods/)
Great example tutorial can be found here:
http://blog.sigmapoint.pl/developing-static-library-for-ios-with-cocoapods/
Enjoy!
Related
I have an Objetive-C project that builds an iOS framework. It is currently in a subfolder in a git repo hosted on github. I want to distribute the code that is in the iOS framework as a Cocoapod. I have a couple of specific questions.
First, do I need to make a separate repo with just the code for the framework?
Second, does Cocoapods always build my code into a static library? It is OK if that is the case - static libraries are fine - but I'll have to make changes that affect other projects if we are switching from a framework (which is ultimately a dynamic library) to a static library. I would prefer to know whether it is possible to have Cocoapods build a framework and whether that is a good idea or more trouble than its worth.
Thanks!
I'll tell you what I've done in my projects.
I have an Objetive-C project that builds an iOS framework
So you already know hot to make a framework. Otherwise I would have suggest you to read these wonderful tutorial from www.raywenderlich.com
https://www.raywenderlich.com/5109-creating-a-framework-for-ios
https://www.raywenderlich.com/2430-how-to-create-a-framework-for-ios
First, do I need to make a separate repo with just the code for the
framework?
For my development
I've done a separate repo with all the framework/library (shared code) and added it as a git submodule in my project(s).
git submodule add https://github.com/me/MyFramework
When I brand new clone my project I init my submodules with this commands:
git submodule update --init --remote
git submodule foreach git checkout master // this only if you wanna the master commit and not be in a detach state
You can also lock a submodule to a particular commit or tag or branch of your separate repo by adding
branch = commit|tag|branch
in your .gitmodules file
I've made the framework as a Framework Pod as explained here:
https://www.raywenderlich.com/5109-creating-a-framework-for-ios
And I use it as a development pod by specifying in my main project Podfile the path as a relative pat '../my_framework_pod'
platform :ios, '12.0'
target 'MyMainAwsomeProject' do
use_frameworks!
pod 'MyFramework', :path => '../MyFramework'
end
If you wanna import it not as development pod (the code will be readonly) you could put the git repo URI instead of the relative path.
Second, does Cocoapods always build my code into a static library?
To be honest, I've always seen it as a static library. But this is the static library of the whole of all the Pods you are using in the main project.
But it should be quite painless for you as you need only to change how to use it. By adding your framework to the Podfile along with all the other Pods you are already using.
You would add it only to your main project Podfile and when you type pod install it's up to the pod command to create the correct workspace.
Hope to have shown you a valid and nice journey to make.
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.
Currently we need to work with a library which has been merged into another project. That library has its own podspec and was previously available as a remote pod from its own git repo. After it was merged in the big project, the big project uses that pod with a local path.
We still need that library in our project but fetching the whole "merged" project for that pod does not seem legit.
Is there any way to specify a path in the Podsfile which would be able to retrieve the pod from a folder inside an existing git repo?
As I understand you - you're trying to fetch some existing part of the repo as a cocoapod.
So, if this library is not a pod itself - no, it's not possible. You can install libraries (read frameworks) via cocoapods only if they have a pod published, or created by you locally.
You basically have two options here:
Move this code to git-submodule and use it in both projects
Create a pod by yourself (locally, or publish it) and use it in both projects via cocoapods
The second way is preferable, cause cocoapods themselves save you a lot of nerves during construction or maintenance.
If you want some help on any approach - feel free to ask here.
So I can tell CocoaPod's pod install the location of a project directory (with --project-directory). It will the apparently look for Podfile, *xcproject/ and create or update *.xcworkspace/ there.
Is there also an option for telling it that an existing workspace resides in a different directory from this project or the current directory?
The reason I am asking is described in this related question.
CocoaPods docs states:
workspace
Specifies the Xcode workspace that should contain all the
projects.
If no explicit Xcode workspace is specified and only one project exists in the same directory as the Podfile, then the name of that project is used as the workspace’s name.
Example:
workspace '../MyProject'
workspace 'folder/AnotherProject'
I have created a new cocoa pod using
pod lib create SamplePod
It set me up with a well thought out library structure. So I created new file by making a group (SamplePod) inside Pod folder "Sample.h" and when trying to access it using
#import <SamplePod/Sample.h>
It couldn't able to identify the file.
Can anybody explain where to add new files for pod and how to refer them in pod sample project ?
I have already refered these links
(1) http://guides.cocoapods.org/making/using-pod-lib-create
(2) http://guides.cocoapods.org/making/making-a-cocoapod.html
You should store files that are actually part of your CocoaPod in the the location specified for source_files in your podspec (e.g. Pod/Classes).
So, if you are adding new files, you should put them in that directory, and you can then put them in a sensible group folder within Xcode.
If you are copying an existing file to the project (that is part of your actual pod), you should copy them to the same directory above, and you can then add them to your example project by going to File > Add Files to "MyProject" ... (you should un-tick the Copy items to destination group's folder).
They can then be imported with the usual #import "MyFile.h"
It's better to run
Pod install
After adding new files. Then you can easily import these files to your CocoaPod sample project.For more details you might want to check this out