iOS primary development study notes: CocoaPods use

This paper draws on CocoaPods use , combined with some of their own practice, carried out study notes summary, something relatively simple and obvious, is designed to quickly realize the import and use CocoaPods can cite the tripartite library.

Why CocoaPods

In iOS development, will inevitably use some tripartite library, and if we want to manually import-party libraries, it will spend a lot of time and effort, and even lead to confusion, mistakes. Take a similar situation and said: I am doing a demo at the first time, there have been non-stop error, and then goes on to import-dependent problem tripartite library, doing pretty confusion and irritability. And CocoaPods this package depends on the good management tool to help us manage the tripartite library. Makes clear tripartite library management, increase efficiency.

Installation CocoaPods

Use the terminal to install, simple to realize a few lines of command

  • CocoaPods ruby ​​source code is written, we should first check whether there are ruby ​​environment
ruby --version
  • ruby source software using the Amazon cloud services, general domestic network is not accessible. If you can not access, ruby ​​source can be replaced by domestic Taobao Source:
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
// 如果只有一个淘宝的源,说明更换源成功
gem source -l
  • When finished, use the gem command to install CocoaPods:

sudo gem install cocoapods

  • After successful installation, prior to use, but also for CocoaPods initialization:

pod setup

  • Check whether the installation was successful:

pod --version

Use CocoaPods import-party libraries

  • We enter into the project and .xcodeproj same level folder, create a new file and enter the edit Podfile, such as:
platform :ios, '8.0'
inhibit_all_warnings!

 target 'PrivateTutor' do
pod 'AFNetworking'
pod 'FMDB', '~> 2.7.5'

end

Podfile file needs to specify the platform, the system is the minimum version iOS or macOS, and third-party libraries to be supported. After a target, there may be a plurality of Podfile target. For example, plug-in development, the main projects and plug-in project depends package may be different, you can write two target, are set dependent on third-party libraries.

We need to import a third-party library, just in between do and End pod 'package name', if the version number waspod 'package name', 'version number'

The version number representation as an example, the most commonly used ~>, that 'FMDB', '~> 2.7.5'represents a compatible version of the latest version 2.7.5

  • We need to add or delete dependence upon third-party libraries, modify Podfile file. After modification execute the following command to install depends tripartite library: pod install

    Updated with this command:pod update

  • Upon completion there will be .xcworkspace file directory, after we open the file from the project.

  • Pods will appear engineering, CocoaPods will all depend on third-party libraries into a Pods project.

  • We use the tripartite library project, the direct import-party libraries can be imported.

Guess you like

Origin blog.csdn.net/weixin_34259159/article/details/90864025