cocoapods有很多值得學(xué)習(xí)的地方,自己也被cocoapods坑了很多次,所以想要認(rèn)真的了解一下cocoapods。一點(diǎn)一點(diǎn)的學(xué)習(xí)吧。
首先,使用cocoapods都是從執(zhí)行pod命令開(kāi)始的,先看看pod命令都干了些什么。
先看看pod命令在哪里
$ where pod
/usr/local/bin/pod
對(duì)應(yīng)的文件找到了,看看這個(gè)文件的內(nèi)容
$ cat /usr/local/bin/pod
#!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'cocoapods' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0.a"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
end
load Gem.activate_bin_path('cocoapods', 'pod', version)
這是一個(gè)ruby文件,不先了解ruby是沒(méi)辦法繼續(xù)下去了,先去看看ruby。
1 require 'rubygems'
2
3 version = ">= 0.a"
4
5 if ARGV.first
6 str = ARGV.first
7 str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
8 if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
9 version = $1
10 ARGV.shift
11 end
12 end
13
14 load Gem.activate_bin_path('cocoapods', 'pod', version)
第一行相當(dāng)于import吧,加了個(gè)什么東西進(jìn)來(lái)
第三行定義了一個(gè)變量version,賦值 ">= 0.a"
第五行的ARGV代表參數(shù),執(zhí)行pod update, ARGV.first就是update
第八行的str =~ /\A_(.*)\z/是正則匹配,應(yīng)該是匹配以 "_" 開(kāi)頭并以 '' 結(jié)尾的字符串,不知道什么時(shí)候會(huì)執(zhí)行到9和10兩句,一般應(yīng)該是不會(huì)
第十四句 Gem.activate_bin_path('cocoapods', 'pod', version)在我的環(huán)境里的返回是
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.1/bin/pod
然后
load "/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.1/bin/pod"
也就是執(zhí)行這個(gè)文件了。這個(gè)文件得好好看看,ruby好多還看不懂,需要頻繁百度。