Some slightly more advanced uses of CocoaPods

Some slightly more advanced uses of CocoaPods

[[150180]]

I remember when I first started iOS development, there was no project dependency management tool. When you need to introduce a third-party library, it is quite troublesome. You either need to copy the library directly or add a dependency project. This situation did not change until CocoaPods came out. Project dependency management is not the first of its kind in CocoaPods. It has already appeared in many other project developments and has even become a standard feature of development. Despite this, CocoaPods still makes a huge contribution to iOS/Mac development. I would like to express my gratitude to those who have contributed to CocoaPods.

CocoaPods is not very powerful, but it is useful enough most of the time. Just the most basic sample configuration can meet most of the needs of your project, but knowing more about some of its features will make you more comfortable.

Specify Source

CocoaPods supports private Spec repositories. We can build our own sources or use unofficial sources. As long as they comply with the regulations, they can be specified.

  1. source 'https://github.com/artsy/Specs.git'    
  2. source 'https://github.com/CocoaPods/Specs.git'    

Suppress warnings

The inhibit_warnings parameter can effectively suppress warnings generated by third-party code libraries introduced by CocoaPods.

All can be specified.

  1. inhibit_all_warnings!

Can also be targeted.

  1. pod 'ReactiveCocoa' , '~> 2.4' , :inhibit_warnings => true    

Use the branch pointed to by git's HEAD

  1. pod 'ISO8601DateFormatter' , :head

Using the master branch

  1. pod 'ARAnalytics/Mixpanel' , :git => 'https://github.com/orta/ARAnalytics.git'    

Specifying a branch

  1. pod 'Reachability' , :git => 'https://github.com/ashfurrow/Reachability.git' , :branch => 'frameworks'    

Specify tags

  1. pod 'AFNetworking' , :git => 'https://github.com/gowalla/AFNetworking.git' , :tag => '0.7.0'    

Specify commit

  1. pod 'ARTiledImageView' , :git => 'https://github.com/dblockARTiledImageView' , :commit => '1a31b864d1d56b1aaed0816c10bb55cf2e078bb8'    

Using sub-libraries

It can be like this

  1. pod 'QueryKit/Attribute'    

You can also specify multiple sub-libraries like this

  1. pod 'QueryKit' , :subspecs => [ 'Attribute' , 'QuerySet' ]

Using native code

You can specify local code through :path, but you need to make sure the directory contains a podspec file.

  1. pod 'AFNetworking' , :path => '~/Documents/AFNetworking'    

Specify the target's dependent library

  1. target :ZipApp do    
  2. pod 'SSZipArchive'  
  3. end

Exclude tags

  1. target 'Artsy Tests' , :exclusive => true   do    
  2. pod 'FBSnapshotTestCase' , '1.4'  
  3. end

Specifying xcodeproj

By default, the first xcodeproj in the same directory as the Podfile file will be used, but you can also specify

  1. xcodeproj 'MyProject'  
  2.  
  3. target :test do    
  4. # This Pods library links with a target in another project.
  5. xcodeproj 'TestProject'  
  6. end

Specify the target of the connection

If you do not explicitly specify a target to connect to, Pods will connect to the first target of the project by default. If necessary, you can use link_with to specify one or more targets to connect to.

  1. link_with 'MyApp' , 'MyOtherApp'    

Specify the environment

The following will only add the PonyDebugger library to the project under the Debug environment.

  1. pod 'PonyDebugger' , :configuration => [ 'Debug' ]

Specify the target configuration file

  1. xcodeproj 'TestProject' , 'Mac App Store' => :release, 'Test' => :debug

Use Dynamic Frameworks instead of Static Libraries

This feature can be enabled by using the flag use_frameworks! If you need to use Swift libraries, you must add this flag.

Speed ​​up pod install/update

When using CocoaPods to add third-party libraries, whether executing pod install or pod update, it often gets stuck at Analyzing dependencies. This is caused by updating the local pod spec file. The --no-repo-update flag can be used to not update the local pod spec index. Of course, the first install should not add this flag, but it can be used appropriately when modifying the Podfile later to speed up the pod.

  1. pod install --no-repo-update
  2. pod update --no-repo-update

Output detailed log

  1. pod update --verbose

Cocoapods plugin for XCode

cocoapods-xcode-plugin is an XCode plug-in that allows you to easily operate Cocoapods. It is a very useful plug-in.

END

My level is not good enough, if there are any mistakes, please correct me.

<<:  Planning introduction: numerical design starts from these three aspects

>>:  The future of Android - PC-based

Recommend

Hydrogen energy, it’s not easy to say I love you

Excerpted from: Inside and Outside the Classroom ...

TCL plus BlackBerry tells us that 1+1 is likely to be less than 2

In the Chinese and even global mobile phone market...

Low cost and high activity, how to recall users?

What I will talk about today is mainly related to...

Have you paid attention to these "bullshit" things?

Whether at home, in the elevator, on the subway, ...

Optimization of iOS photo album Moment function

Recently, I am developing the Gallery module of m...

The secret behind the rapid growth of Airbnb and YouTube users...

Why is YouTube the fastest growing company in Sil...

How to carry out user stratification operation with millions of IPs?

This article mainly talks about how million-dolla...