Skip to content

Instantly share code, notes, and snippets.

@vigneshr89
Last active July 26, 2016 15:18
Show Gist options
  • Save vigneshr89/de5cf3c2fe9bbf4c7a2c to your computer and use it in GitHub Desktop.
Save vigneshr89/de5cf3c2fe9bbf4c7a2c to your computer and use it in GitHub Desktop.
Cocoapods
Jargons:
• Cocoapods
o It is a tool written in ruby to help with your pods
• Pod
o Pod is a simple ruby file to specify project dependencies.
o Typically, the pod file is placed in the app’s project directory
o The Pod lists the dependencies of the app.
o The dependencies can be a remote or local repository.
o Cocoapods supports GIT, mercury and SVN.
• Podspec
o A configuration file in JSON or Ruby.
o Specifies everything about a component.
o The pod spec contains details such as Name, Version, Summary, Author, License, Component home page, public header files, Source files, resources, dependencies, flags etc.
Commands:
Consumer side commands:
1. $ pod init
Creates an empty pod file.
2. $ pod install
This command reads the pod file and set up the dependencies magically in the consumer application.
3. $ Pod update
This command updates the consumer app dependencies based on the pod file.
Components side commands
1. “$ pod spec create <Component Name>”
Creates a template podspec file.
Process:
If you are component developer
• Create your component
• Create a pod spec file
• If you are planning to host it in some server like GitHub, it is important to tag your revision. For ex, if you want to create spec for v1.0.0 (Follow this standard version convention), you have to create a tag on a commit that says 1.0.0.
• There are other ways (revision string) to point a commit. But tagging is best.
• The spec can be submitted to global repository, pod install command will get your podspec by checking the global repo.
• If you are not hosting podspec in global repo consumer will have to provide absolute path of spec in the pod file.
If you are consumer
• Install cocoapods
• Create a pod file using “pod init”
• Add your dependencies in the pod file. Generally the component creaters would have specified what to add to get their component.
• Install pod file using “pod install”
• Use the .xcworkspace instead of .xcodeproj.
• And that’s all.
Frequently Asked Questions:
1. How do I install cocoapods?
$ sudo gem install cocoapods.
Note:
Make sure to check http_proxy and https_proxy environments variables
are set in your terminal.
$ export http_proxy=http://username:password@<proxy_server>:port
2. I don’t have sudo rights. How do I install cocoa pods?
$ gem install cocoapods --user-install
Note:
Make sure to add the command path in the $PATH variable. The command path can be obtained by “$ gem which cocoapods”.
3. Where do I find a sample pod spec submitted to global repo?
There are many OSS pedspecs available in global spec repo. For example , take a look at iRate.
4. How do I submit my podspec to global repo?.
Submit your podspec to https://github.com/CocoaPods/Specs . It is important to make sure the podspec really works. Otherwise it will create a bad name for the community.
When the podspec is submitted with a version, say v1.0.0, the component can be added like pod ‘MyComponent’ , ‘ ~> 1.0.0’ .
5. How do I create a podspec for locally available files?
For remote files the source property is set to something like the iRate example given below.
For locally available files you would remove the source key from the spec. That’s all.
6. How do I create a pod file for locally available component?
Refer: https://guides.cocoapods.org/syntax/podfile.html#pod
iRate POD SPEC
{
"name": "iRate",
"version": "1.11.4",
"license": "zlib",
"summary": "A handy class that prompts users of your iPhone or Mac App Store app to rate your application after using it for a while.",
"homepage": "https://github.com/nicklockwood/iRate",
"authors": "Nick Lockwood",
"source": {
"git": "https://github.com/nicklockwood/iRate.git",
"tag": "1.11.4"
},
"source_files": "iRate/iRate.{h,m}",
"resources": "iRate/iRate.bundle",
"requires_arc": true,
"platforms": {
"ios": "4.3",
"osx": "10.6"
}
}
My PodSpec:
{
"name": "MyCocoaComponent",
"version": "2.0.0.40",
"license": "MIT",
"summary": "A pretty cool library. You probably never heard of it.",
"homepage": "http://www.allforios.wordpress.com",
"authors": {
"Vignesh Ramanahan": "vickyunderthesky@gmail.com"
},
"social_media_url": "https://twitter.com/allforios",
"source": {
"http": "http://localhost:8080/job/Framework-iOS-MyComponent/40/artifact/Artifacts/40/Universal/MyCocoaComponent.framework.zip"
},
"source_files": "MyCocoaComponent/MyCocoaComponent.framework/Headers/*.h",
"preserve_paths": "MyCocoaComponent/MyCocoaComponent.framework",
"platforms": {
"ios":"8.0"
},
"vendored_frameworks": "MyCocoaComponent.framework"
}
POD File Example : My Cococa Component
# Uncomment this line to define a global platform for your project
platform :ios, '9.2'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'PodDependencyTest' do
pod 'MyCocoaComponent' , :podspec => "http://localhost:8080/job/Update-pod-repo/lastSuccessfulBuild/artifact/PodRepo/MyCocoaComponent/2.0.0/MyCocoaComponent.podspec.json"
end
Example 2:
workspace './BAMobile.xcworkspace'
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'MobileAppCore' do
pod "ContextLib", :podspec => "/Users/abcd/Desktop/PodSpecRepo/ContextLib/ContextLib.podspec"
xcodeproj "./MobileAppCore/MobileAppCore.xcodeproj"
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['PUBLIC_HEADERS_FOLDER_PATH'] = 'MobileAppCoreHeaders'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment