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里对导入dependencies的片段的管理工具。
Cocoapods的原理是将所有的依赖库的源码下载到本地一个名为Pods的目录中,并进行编译。开发者只需' pod init '命令创建一个Podfile文件,书写需要的依赖,然后cd到工作目录下' pod install '命令即可下载。

2、cocoapods的下载(Mac M1,Ventura)
cocoapods使用ruby语言编写的,而ruby库和程序是由Gem标准包管理的,ruby版本是由RVM(Ruby Version Manager)管理的。
所以大致步骤就是利用Gem安装好Ruby环境,用rvm list 查看是否安装ruby及其版本,rvm list known命令找到最新版本并下载,然后利用Ruby下载cocoapods。
但是实际会遇到很多问题,按网上步骤和官方文档未必成功,找准自己哪一步出了什么问题,针对性多方参考。最终在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/则是被墙的状态,则使用gem sources --remove [默认源],再用gem sources -a https://gems.ruby-china.com/,就成功加入了调查兵团。如果这个不起作用了,那就是又炸了,网上找找最新的域名。

用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 anend
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: