首页 > 解决方案 > 有没有可以修改 Podfile 的命令行工具?

问题描述

我想使用 Cocoapods 为我的项目添加一个框架。但我不想手动更改 Podfile。我想使用命令行来编辑 Podfile,如下所示:

some_command ./Podfile --add AFNetworking --target MyTarget

可能吗?

标签: iosxcodecocoapodspodfile

解决方案


不幸的是,没有这样的命令。

您可以做的越近,就是创建一个.sh打开Podfile并在其上写入的文件。例子:

podwrite.sh

#!/bin/sh

FILE="Path/To/Podfile"

/bin/cat <<EOM >$FILE
source 'https://github.com/CocoaPods/Specs.git'

target 'MyTarget' do
  use_frameworks!
  pod 'AFNetworking'
end

EOM

通过终端调用:

sh podwrite.sh

podfile 上的输出:

source 'https://github.com/CocoaPods/Specs.git'

target 'MyTarget' do
  use_frameworks!
  pod 'AFNetworking'
end

推荐阅读