CocoaPods的Podfile文件编写


一、Podfile文件

platform :ios,'7.0'
# 去掉来自cocoapods的所有警告
inhibit_all_warnings!
def commonPods
    pod 'AFNetworking', '~> 2.5.0'
    pod 'SDWebImage', '~> 3.7.1'
    pod 'YYModel', '~> 1.0.4'
    pod 'UEKFoundation', :git => 'https://github.com/yangyongzheng/UEKFoundation.git'
end
target 'TestApp' do
    commonPods
end
target 'TestAppTests' do
    inherit! :search_paths
end

二、Podfile语法参考

Podfile Syntax Reference官网

1)永远使用最新版:pod 'YYModel'

2)使用固定版本:pod 'YYModel', '1.0.4'

3)操作符:

  • = 0.1 Version 0.1.
  • > 0.1 Any version higher than 0.1.
  • >= 0.1 Version 0.1 and any higher version.
  • < 0.1 Any version lower than 0.1.
  • <= 0.1 Version 0.1 and any lower version.
  • ~> 0.1.2 Version 0.1.2 and the versions up to 0.2, not including 0.2. This operator works based on the last component that you specify in your version requirement. The example is equal to >= 0.1.2 combined with < 0.2.0 and will always match the latest known version matching your requirements.

三、workspace多工程联编Podfile文件编写

# 多工程联编Podfile文件配置
workspace 'YZWorkSpace'     # 需要生成的workspace的名称
# project 'path' 指定包含Pods库应链接的目标的Xcode项目,其中path为项目链接的路径
# 对于1.0之前的版本,请使用xcodeproj
project 'YZToolsLib/YZToolsLib' # 工具库工程
project 'YZToolsDemo/YZToolsDemo'   # 实例工程
platform :ios, '7.0'
inhibit_all_warnings!   # 禁止CocoaPods库中的所有警告。
def commonPods
    pod 'FMDB'
end
# This Target can be found in a Xcode project called `ToolsSDK`
# 工具库工程需要引入的第三方库
target 'YZToolsLib' do
    project 'YZToolsLib/YZToolsLib'
    commonPods
end
# Same Podfile, multiple Xcodeprojects
# 实例工程需要引入的第三方库
target 'YZToolsDemo' do
    project 'YZToolsDemo/YZToolsDemo'
    commonPods
end

项目目录结构树如下:


CocoaPods的Podfile文件编写_第1张图片
多工程联编项目目录结构树.png

注:tree -L N这个命令,只查看当前第N级的目录和文件。

  • 此命令需要安装tree,安装命令:brew install tree
  • 安装brew命令:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • brew官网

你可能感兴趣的:(CocoaPods的Podfile文件编写)