Using the Cocoapods problem solution in iOS projects

Source: Internet
Author: User

Wen/yehot (author of Jane's book)
Original link:
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

Why should I use Cocoapods as a third-party dependency management tool in iOS projects?

(End of full text)

A joke.
The real reason is this:


  • From a bug.
  • Analysis Requirements and Solutions
  • Identify scenarios
  • Cocoapods Learning Materials

First, from a bug said:

1, the company's project unified use of SVG format pictures;
2, on GitHub, there is only one star number more than 1000 SVG parsing library, called Svgkit. (yes, that's the pit-daddy's Vault)
    Pit 1: This library has been using non-arc, there are more than 100 classes;
    Pit 2: This library also relies on another library cocoalumberjack;
    Pit 3: configuring this library into a project will report an error:

3, the company's project is directly in the form of source code to use the library.
The result is that Build Phase :
(I don't know if the people who added these-fno-objc-arc marks collapsed, I just looked at the faint worry: how much longer? Leak or extra, it's a pit. )

4, because of the source code, the Svgkit version of the project will not be updated for a long time. caused by the iphone6s above equipment, because the old version of the library does not fit 6S, will collapse. Now you have to update to the latest version of this library.

second, the exploration of the solution:

Programme one:

Replace the old source files with the latest source code
Problem: 1, too many types of files, trouble, error prone;
2, there will be a lot of-fno-objc-arc mark, very annoying;
Conclusion: veto

Scenario Two:

Svgkit Author Recommendation--Static library (the GitHub page of this library only describes this one usage)
Problem: 1, only. h header file, error cannot be located and modified.
2, the static library uses the category must add-OBJC mark.
3. The static library. A file needs to differentiate between the device version and the simulator version, or use it after merging.
Conclusion: veto

About question 2 here to explain, there was no problem, but I unfortunately encountered this pit :
1, the static library if the categoryis used, you need to add -OBJC mark. Otherwise, it crashes when it is used:

2, it took a long time did not solve the problem is that I remember the set up AH.
Later only to think of hair or collapse, this is our project target, you feel the following:

If any of the target settings are forgotten, a hole is buried again.
3, about Why to add-OBJC Mark problem, has previously looked for information, here is completely because of the target too many omissions caused.

The notes are as follows:

The role of the-OBJC tag:

  • Using a third-party library, the use of this library in the wizard, in particular, after the library is added, you need to add the-OBJC flag in the other Linker flags under the Xcode build settings. The use of this flag is related to an important feature of OBJECTIVE-C: category. As explained here, there are some conflicts between the standard static library implementation of UNIX and the dynamic nature of Objective-c: Objective-c does not define a link symbol for each function (or method), it creates a link symbol for each class.
  • This way, when you use categories in a static library to extend an existing class, the linker does not know how to integrate the methods in the original class with the method in the category, causing you to invoke the method in the category with "selector not recognized", which means that the method definition error is not found.
  • In order to solve this problem, the-OBJC flag is introduced, and its function is to load all the object-related files in the static library.
  • This can solve the problem, but in the 64-bit Mac system or iOS system, the linker has a bug, will cause only a class of static libraries can not use the-OBJC flag to load the file. The workaround is to use the-all_load or-force_load flag, which is to load all the files in the static library, but All_load works on all the libraries, and the-force_load must specify the specific file later.

Programme III:

Using CocoaPods
Question: The author does not indicate whether the library supports Cocoapods
That's why I didn't even consider switching to CocoaPods at first.

    • Here you are prompted to test whether a library supports cocoapods using the following command
      $ pod try XXX

      Since this is not an introduction to how to use CocoaPods, here are just a few of the benefits of using CocoaPods, as well as some usage experience (I'll list some CocoaPods in the following article).

1, solves the plan one, needs in the project the massive marking-fno-objc-arc question:
--cocoapods automatically generated association libraries are automatically tagged in the associated project and only works in the original project.
2, solved the program two, only. h header file, no source code , error cannot locate and modify the problem:
--cocoapods also uses static library dependencies, but retains all. m files
3, solves the scenario two, the static library uses some pits, and needs the packing. A file troublesome operation .
--cocoapods Auto-complete
4, greatly simplifies the operation :
1> CD into the directory where the. xcodeproj file is located
  $ pod init
2> in the automatically generated Podfile file, add the name of the library to pod
  $ pod install
3> 's done.
5, the most important point: in the future to meet the need to upgrade the third-party library version, just one line of command:
  $ pod update
Conclusion: This is it!

Identify scenarios

CocoaPods resolves the issue of third-party library version upgrades once and for all.

Just the sauce ~

Dry Parts

Cocoapods Learning Materials

Cocoapods Getting Started:

1. Cocoapods Installation and Use tutorial
(This is enough for a primer)
2, CocoaPods pod install/pod update slow issue
Recently used Cocoapods to add a third-party class library, whether the pod install or pod update is stuck in the analyzing dependencies
The reason is that when executing the above two commands will upgrade the Cocoapods spec warehouse, add a parameter can omit this step, and then the speed will be improved a lot. The command is as follows:

install --verbose --no-repo-updatepod update --verbose --no-repo-update

3, Mac upgrade to 10.11,cocoapods no
Use the command line sudo gem install cocoa pods error, change to sudo gem install-n/usr/local/bin cocoa pods, see: Http://
4, the use of experience:
1> pods Install, the version number can be added (the latest version of the corresponding library is downloaded by default)

However, after downloading the dependencies, it is best to add the version number to avoid the instability caused by the frequent upgrades of some third-party libraries when new libraries are added or pod update.

2> Multi-person cooperation of the larger project, Podfile file can set permissions, only one person to modify, add dependent libraries.
3 > SVN or git do version management, do not upload Pods, workspace directory:
(Ignore can be set)

Cocoapods High-Order Usage:

1. Even if you don't use a third-party library, Cocoapods is still a great tool for managing code dependencies
2. Use Cocoapods to integrate into your project with the GitHub managed category
3. Cocoapods Create Private Podspec
4, write a pod published to Cocoapods
5, cocoapods Some of the slightly higher use of the slightest

//TODO:1、利用多个 project 做本地依赖管理       2、私有仓库的使用尝试

    Recommended expand Reading Copyright belongs to the author

    Using the Cocoapods problem solution in iOS projects

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.