cocoapods筆記1
1、什么是cocoapods?
CocoaPods manages library dependencies for your Xcode projects.
The dependencies for your projects are specified in a single text file called a Podfile. CocoaPods will resolve dependencies between libraries, fetch the resulting source code, then link it together in an Xcode workspace to build your project.
Ultimately the goal is to improve discoverability of, and engagement in, third party open-source libraries by creating a more centralised ecosystem.
簡言之,相當于java項目中maven所承擔的依賴管理部分的功能,相當于Android Studio里的build.gradle里對導(dǎo)入dependencies的片段的管理工具。
Cocoapods的原理是將所有的依賴庫的源碼下載到本地一個名為Pods的目錄中,并進行編譯。開發(fā)者只需' pod init '命令創(chuàng)建一個Podfile文件,書寫需要的依賴,然后cd到工作目錄下' pod install '命令即可下載。

2、cocoapods的下載(Mac M1,Ventura)
cocoapods使用ruby語言編寫的,而ruby庫和程序是由Gem標準包管理的,ruby版本是由RVM(Ruby Version Manager)管理的。
所以大致步驟就是利用Gem安裝好Ruby環(huán)境,用rvm list 查看是否安裝ruby及其版本,rvm list known命令找到最新版本并下載,然后利用Ruby下載cocoapods。
但是實際會遇到很多問題,按網(wǎng)上步驟和官方文檔未必成功,找準自己哪一步出了什么問題,針對性多方參考。最終在https://www.moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/#step-2-install-chruby-and-the-latest-ruby-with-ruby-install
使用'?gem sources -l '命令查看Ruby鏡像,如果不是
https://gems.ruby-china.com/則是被墻的狀態(tài),則使用gem sources --remove [默認源],再用gem sources -a?https://gems.ruby-china.com/,就成功加入了調(diào)查兵團。如果這個不起作用了,那就是又炸了,網(wǎng)上找找最新的域名。

用sudo gem install cocoapods嘗試是否可以下載。
3、cocoapods使用
·Step 1:
Check the?cocoapods.org?to make sure the libraries you would like to use are available.
https://cocoapods.org/
·Step 2:
Create a?Podfile, and add your dependencies:
Run?$ pod install
?in your project directory.
Open?App.xcworkspace
?and build.
To create a new project with CocoaPods, follow these simple steps:
Create a new project in Xcode as you would normally.
Open a terminal window, and?
$ cd
?into your project directory.Create a Podfile. This can be done by running?
$ pod init
.Open your Podfile. The first line should specify the platform and version supported.
In order to use CocoaPods you need to define the Xcode target to link them to. So for example if you are writing an iOS app, it would be the name of your app. Create a target section by writing?
target '$TARGET_NAME' do
?and an?end
?a few lines after.Add a CocoaPod by specifying??
pod '$PODNAME'
?on a single line inside your target block.
Save your Podfile.
Run?
$ pod install
Open the?
MyApp.xcworkspace
?that was created. This should be the file you use everyday to create your app.
Integrating CocoaPods with an existing workspace requires one extra line in your Podfile. Simply specify the?.xcworkspace
?filename in outside your target blocks like so: