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

30-minute Douyin live streaming sales speech process!

The three most critical steps in live streaming s...

How to avoid invalid traffic and improve traffic quality in bidding promotion?

Today’s sharing content is about the details of d...

Qianmeng Online Earning 36 Strategies Full Course

Preface to Qianmeng.com’s 36 Strategies for Makin...

Three key words for Internet business: product, traffic, and conversion rate

Traffic operation cannot be carried out blindly w...

Can't quit smoking? Going cold turkey actually works

This is the 4712th article of Da Yi Xiao Hu Cold ...

iOS 18 is about to be released, get to know the new features first

The May Day holiday is approaching, which means i...