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

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.

Related

Unable to install AFNetworking and Google-Maps-iOS-Utils together

I need to use Afnetworking and google-maps-ios-utils both in my project but using pods it is not possible. because Afnetworking don't work if I comment # use framework! in my pod file and google-maps-ios-utils don't work if I uncomment it.
I tried manually installing google-maps-ios-utils but it still give me error related to bridging header.
Is there any way to use both library together.
Or how to install AFnetworking or google-maps-ios-utils manually to avoid this clash.
I need some alternative for google-maps-ios-utils because it is only works if I comment #use_frameworks! in pod file , and if I comment it most of other library such as FBSDKLoginKit and SDWebimage get error.
Xcode 10, swift 4.
Have you try this on your pod file like below,
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
def share_pods
# Pods for your target name
pod 'AFNetworking', '~> 3.0'
pod 'GoogleMaps'
end
target 'your target name' do
share_pods
end
Hope it's help you:)

Adding Mongodb to ios project

I am currently adding monogodb to my ios project. Just after following the instruction stitch mongodb offered, I am stuck at when pod installing StitchCoreSDK. It supposed to create a xcworkspace file, but it didn't. Instead, I got the following message.
enter image description here
The podfile I create is like following
# Uncomment the next line to define a global platform for your project
platform :ios, '11.4'
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'paotuaniOS' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
# Pods for paotuaniOS
pod 'Nexmo-Stitch'
pod 'StitchSDK', '~> 4.0.5'
target 'paotuaniOSTests' do
inherit! :search_paths
# Pods for testing
end
target 'paotuaniOSUITests' do
inherit! :search_paths
# Pods for testing
end
end
Can any one help me with this issue?
Thanks!!!
I had this issue before. The repo had problems. The repo has been updated. Please use
pod 'StitchSDK', '~> 4.1.1'

How do I use source in podfile?

I'm new to ios development. For some reason I need to manually set podfile for my Cordova app. There are GoogleCloudMessaging and GGLInstanceID in my podfile, now I want to install a brightcove video player library, the source is https://github.com/brightcove/BrightcoveSpecs.git. However when I add the source on the top of podfile, it seems cocoapods also try to install GoogleCloudMessaging from that source.
My podfile:
source 'https://github.com/brightcove/BrightcoveSpecs.git'
use_frameworks!
platform :ios, '8.0'
target 'myapp' do
pod 'Brightcove-Player-Core/dynamic'
pod 'GoogleCloudMessaging'
pod 'GGLInstanceID'
end
Error:
Analyzing dependencies
[!] Unable to find a specification for `GoogleCloudMessaging`
You need to include the official CocoaPods source:
https://github.com/CocoaPods/Specs.git
Docs:
The official CocoaPods source is implicit. Once you specify another source, then it will need to be included.
So your file should work like this I believe:
source 'https://github.com/brightcove/BrightcoveSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
platform :ios, '8.0'
target 'myapp' do
pod 'Brightcove-Player-Core/dynamic'
pod 'GoogleCloudMessaging'
pod 'GGLInstanceID'
end
Try by giving like:
pod "Brightcove-Player-FreeWheel", :git => 'https://github.com/brightcove/BrightcoveSpecs.git'

Migrating to CocoaPods 1.0.1

I am trying to migrate our existing CocoaPod configuration from 0.39.0 to 1.0.1.
Our existing Podfile looks like:
platform :ios, '9.0'
use_frameworks!
target 'Tools' do
pod 'zipzap', '~> 8.0.4'
pod 'Argo', '~> 2.2.0'
pod 'Curry', :git => 'https://github.com/thoughtbot/Curry.git', :commit => 'eeb459fac309833288e61e134a4e8fad649e99b0'
end
target 'ToolsTests' do
end
This compiled and the tests ran just fine previously. After following the migration guide. I restructured the Podfile like so:
platform :ios, '9.0'
target 'Tools' do
use_frameworks!
pod 'zipzap', '~> 8.0.4'
pod 'Argo', '~> 2.2.0'
pod 'Curry', :git => 'https://github.com/thoughtbot/Curry.git', :commit => 'eeb459fac309833288e61e134a4e8fad649e99b0'
target 'ToolsTests' do
inherit! :search_paths
end
end
This compiles and links just fine. Unfortunately when the tests run they crash with:
2016-06-07 12:04:06.265 xctest[56474:789900] The bundle “ToolsTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2016-06-07 12:04:06.299 xctest[56474:789900] (dlopen_preflight($HOME/Library/Developer/Xcode/DerivedData/Tools-dbmncsubtoarlhhcrpchrswefprz/Build/Intermediates/CodeCoverage/Products/Debug-iphonesimulator/ToolsTests.xctest/ToolsTests): Library not loaded: #rpath/Argo.framework/Argo
Referenced from: $HOME/Library/Developer/Xcode/DerivedData/Tools-dbmncsubtoarlhhcrpchrswefprz/Build/Intermediates/CodeCoverage/Products/Debug-iphonesimulator/ToolsTests.xctest/ToolsTests
Reason: image not found)
Program ended with exit code: 82
In the migration guide it says:
A large fraction of the bug reports we receive is due to ambiguity in the Podfile. It gave a lot of freedom to create all kinds of CocoaPods setups that would work by luck of implementation details, or work but are significantly more complex than they needed to be.
Is this one of those cases that used to "work by luck of implementation details"? If not what is the correct Podfile syntax?
I should note if I duplicate the pod defs in the ToolsTests everything works just fine. Though this feels wrong.
Similar question: Cocoapods testing linker error
Seems to be a common problem people are facing when upgrading. Your new Podfile looks right to me.
If you haven't already, I would try:
cleaning the build folder (in Xcode -> Option+Shift+Command+K)
clearing the derived data folder (rm -rf ~/Library/Developer/Xcode/DerivedData)
clearing your CocoaPods cache (rm -rf ~/Library/Caches/CocoaPods)
and run pod install again
EDIT:
The question I mentioned above has an answer now: https://stackoverflow.com/a/37705768/3067051

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.

Resources