Is it possible to add a local dependency to .podspec file? - cocoapods

I'm using cocoapods now I would like to add a local pod dependency in my project, something like:
s.dependency = 'my pod', :path => ''
but I think is not possibile, some ideas?

I have faced with the same issue and after lot of googling and asking on the CocoaPods github I have finally found the suitable answer.
It's not possible to set a local pod as a dependency, but it's possible to set a pod's source for a specific Podfile, which will work the same way.
E.g., in your podspec, you still have ()
s.dependency = 'my pod', '~> 1.0' # or whatever version you have
Then in your Example/demo/test project's Podfile:
pod 'my pod', :path => '/path/to/the/local/my_pod'
Then just run pod install and you will see both pods as a Development pods.
This way is very useful when you're developing 2 pods (one of which is dependend on the other) simultaneously, yet for release you will still have to publish your pod to the repo (either CocoaPods or a private repo).

Put the local dependency inside your pod's folder root directory,
In your Podspec file, just add s.ios.dependency 'YourRootPodName/YourPodDependencyFolder'
After that, create a subspace like so:
s.subspec 'YourRootPodName' do |ss|
ss.source_files = 'YourRootPodName/**/*.{h,m}'
end
as in this answer Cocoa podspec and path for dependency

Related

Creating new Cocoapod `Unable to find a specification` on pod install

I've gone through the Cocoapod guide for making a new pod.
The repo exists here: https://github.com/kkendall33/QuickInstantiating.
The QuickInstantiation pod spec looks like this:
But when I go to a different project and add QuickInstantiating to the Podfile:
and run pod install. I get this:
I just tested pod install with a different pod and it worked fine. This leads me to believe I'm doing something wrong with mine.
The pod must be pushed before it can be referred to by version. For testing, you can use the same path syntax -
pod 'QuickInstantiating', :path => 'relative/path'
like you used at https://github.com/kkendall33/QuickInstantiating/blob/master/Example/Podfile#L4
Otherwise you can push the pod to a private Specs repo if you do want to test the git repo before pushing the pod to trunk. Instructions at https://guides.cocoapods.org/making/private-cocoapods.

Podspec. Set s.dependency to download forked repo sources

I have a repo that I download via cocoa pods. This repo includes .podspec file which include s.dependency 'glm', '~> 0.9.4.6' line.
as I understood it will download it from here: https://github.com/g-truc/glm
I forked glm and now I want to use s.dependency that is connected to forked repo of glm. How can I specify it in podspec file to point that I need to download forked glm sources?
You can have CocoaPods override a location of a dependency's dependency in your Podfile, i.e. defining pod 'glm', :git => 'https://github.com/yourUser/yourFork.git'
You have to make sure the line where you specify your fork comes before the line that specifies the pod that uses it as a dependency.
See this answer about this topic, and this one about using forks with CocoaPods conveniently.

What is the usage of `podspec` command in Podfile?

There is a command podspec in Podfile (documentation)
Example from the link:
podspec
podspec :name => 'QuickDialog'
podspec :path => '/Documents/PrettyKit/PrettyKit.podspec'
What is really mean? a example of project structure that use podfile will be really appreciated
I know this is old , but I stumble on this question , while learning Cocoapods distribution.
So here is the answer:
As the documentation says. If you define this in your Podfile. All dependencies that you define in your podspec will be installed.
Example:
in your .podspec file you have:
spec.dependency "RealmSwift", "~> 0.99.0"
spec.dependency "Starscream", "~> 1.1.3"
Basically, this means your library/framework uses this dependencies.
When you are working on your library, you still need to install this dependencies. So you define them in the Podfile of your library:
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'YourLibrary' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for YourLibrary
pod "RealmSwift", "~> 0.99.0"
pod "Starscream", "~> 1.1.3"
target 'YourLibraryTest' do
inherit! :search_paths
# Pods for testing
end
end
now instead of re-writing all of those dependency that your library needed. You could just use
# Pods for YourLibrary
podspec
this will look through your library/frameworks podspec file. And download the dependencies that were defined.
From the documentation of Cocoapods:
It is intended to be used by the project of a library.

Kiwi and CocoaPods with a static shared library

I have a workspace with 3 projects:
MyApp
Common
Pods
Common is a common library that MyApp depends on. I'd like to setup CocoaPods and Kiwi to work correctly in this project. How do I go about this?
I found https://stackoverflow.com/a/16472563/62, but when I try to follow this approach, I get an error when building MyApp before I even try adding Kiwi:
ld: library not found for -lPods
Here's the repo on GitHub: https://github.com/lyahdav/cocoapods_kiwi_shared_library
My Podfile is:
workspace 'MyApp.xcworkspace'
platform :ios, '7.0'
target 'Common' do
xcodeproj 'Common/Common.xcodeproj'
pod 'AFNetworking'
pod 'Reachability'
target 'MyApp', :exclusive => true do
xcodeproj 'MyApp.xcodeproj'
end
end
I finally found a working solution for this. Here's the Podfile:
platform :ios, '7.0'
workspace 'MyApp.xcworkspace'
xcodeproj 'MyApp'
pod 'CupertinoYankee', '~> 1.0'
target :MyAppTests, :exclusive => true do
pod 'Kiwi/XCTest'
end
target :Common, :exclusive => true do
xcodeproj 'Common/Common'
pod 'CupertinoYankee', '~> 1.0'
end
target :CommonTests, :exclusive => true do
xcodeproj 'Common/Common'
pod 'Kiwi/XCTest'
end
This example Podfile shows both MyApp and Common configured to use Kiwi for tests and they can both use pods (CupertinoYankee in this example).
I did manually have to configure in Xcode that MyApp links with Common with these steps:
In MyApp project settings > MyApp target > Build Phases > Link
Binary With Libraries > add libCommon.a
In MyApp project settings > Build Settings > User Header Search Paths > add ${SRCROOT}/Common/Common/**
This repo has a working example: https://github.com/lyahdav/cocoapods_kiwi_shared_library
The only slightly annoying thing I didn't manage to figure out was if there's a way to not duplicate each pod that I want to use both in MyApp and Common. If anyone has a solution that does all of what my solution does and solves that, I'll gladly mark it the accepted answer.
Posted as an edit by anonymous user. Here's his answer:
I have forked the repository and made few changes for new cocoapods versions to make it still working.
platform :ios, '8.0'
workspace 'MyApp.xcworkspace'
project 'MyApp'
target :MyApp do
pod 'CupertinoYankee', '~> 1.0'
end
target :MyAppTests do
pod 'Kiwi/XCTest'
end
target :Common do
project 'Common/Common'
pod 'CupertinoYankee', '~> 1.0'
end
target :CommonTests do
project 'Common/Common'
pod 'Kiwi/XCTest'
end
https://github.com/chrishunterkiller/cocoapods_kiwi_shared_library
I'm not sure how to fix the setup you have, but if I were you I would make Common into its own Pod. Pods can be private and just stored in GitHub as a repo. Of course, you need a podspec for Common but I built a sample to test that setup for our build service and it took me less than 30 mins to get it right.
Then in your Podfile for MyApp, you do something like this:
pod 'Common', :git => 'git#github.com:lyahdav/Common.git', :commit => 'a1b2c3d'
And AFNetworking and Reachability can be referenced in the podspec of Common (assuming that's the right dependency).
This setup also allows you to include Common in whatever other apps you're building without having to embed the code. Again, making assumptions about what you're trying to achieve, so add more detail to the question if that's not right.
You could hack a solution that may get broken again, or better yet as Common is your library, start using CocoaPods for your Common library as well.
It will show up as a local "Dvelopment Pod", which means that you can directly edit the library code as well.
To begin easily just create a Common.podspec at the root folder:
$ pod lib create Common
Then just edit the minimum required parameters, such as platform, source_files, requires_arc and dependency if any.
You can take a look at how your library looks as you change it (and compare it to what you had with your manually created Common library):
$ pod lib lint --no-clean Common.podspec
Finally remove the no-longer needed Common from your workspace and add this to your Podfile:
pod 'Common', :path => '../Relative/Path/To/CommonSources/'
It will take you no more than 30 minutes and you'll learn many things in the process.
Next you could take a look at making private pod repositories.

Reference Specific Commit in a Repo Without Podspec

With cocoapods I'd like to reference a specific commit (without tag) for a repo which does not have a Podspec file - namely SBJSON. How can I specify this? I tried:
pod 'SBJson', :podspec => 'https://raw.github.com/CocoaPods/Specs/master/SBJson/3.1/SBJson.podspec', :git => 'https://github.com/stig/json-framework.git', :commit => '5c4d5f7'
But I cannot both provide :podspec and :git with :commit. What can I do? Do I have to provide my own local Podspec file for this to work?
First off in the case of SBJSON it does have a podspec. You can see it in the specs repo. You can use pod search SBJSON on the command line to see that there is one for it. One thing to keep in mind is that just because the library creator doesn't have the .podspec included in the repo doesn't mean it hasn't been contributed by the community.
But you would have to create a podspec for the repo otherwise. The podspec shows the CocoaPods tool how to include the library into your project.

Resources