IOS 01 CocoaPods 安装与使用

什么是CocoaPods

CocoaPods是一个依赖管理工具,类似Java语言的Maven,Gradle这样的工具;只是他是管理iOS,macOS等平台项目的依赖而已。

同类软件

Carthage,Swift官方提供的Swift Package Manager。

流行程度

CocoaPods>Carthage>Swift Package Manager

更改Gem源

默认的Gem源,在国内访问比较慢,可以使用RubyChina提供的镜像。

gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

查看Gem源

gem sources -l

确保只有 gems.ruby-china.com

安装

sudo gem install cocoapods

初始化

pod setup

查看版本

pod --version

更新

更新gem

sudo gem update --system

安装新版

sudo gem install cocoapods

初始化项目

在项目根目录输入:

pod init

输入 pod init 后,会在当前目录创建Podfile文件,在该文件里面写当前项目依赖的框架。

添加依赖

例如添加QMUI框架,后面我们会讲解使用方法。内容如下:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'MyCloudMusic' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyCloudMusic

  #腾讯开源的UI框架,提供了很多功能,例如:圆角按钮,空心按钮,TextView支持placeholder
  #https://github.com/QMUI/QMUIDemo_iOS
  #https://qmuiteam.com/ios/get-started
  pod "QMUIKit"

  target 'MyCloudMusicTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MyCloudMusicUITests' do
    # Pods for testing
  end

end

安装依赖

pod install

执行pod install 后,会下载依赖库文件到本地,同时需要关闭再重新打开项目。

安装时更新仓库:

pod install --repo-update

重新打开项目

重新打开当前目录下的xcworkspace文件。这是一个工作空间,就是包含多个项目,其中一个项目是我们创建的项目,另一个是Pod项目,因为Pod的原理是将所有依赖保存到Pod项目,我们创建的项目在依赖Pod项目;这样就达到了依赖管理。

相关推荐
humiaor8 小时前
Xcode报错:No exact matches in reference to static method ‘buildExpression‘
swiftui·xcode
归辞...11 小时前
「iOS」viewController的生命周期
ios·cocoa·xcode
crasowas16 小时前
Flutter问题记录 - 适配Xcode 16和iOS 18
flutter·ios·xcode
蒙娜丽宁1 天前
Go语言错误处理详解
ios·golang·go·xcode·go1.19
Johnny Tong2 天前
iOS 18 适配 Xcode 16 问题
ios·cocoa·xcode
键盘敲没电5 天前
【iOS】UIViewController的生命周期
学习·ios·objective-c·xcode
安和昂7 天前
【iOS】UIViewController的生命周期
ios·xcode·swift
Python私教7 天前
Go语言现代Web开发03 关键字和包以及基本数据类型
开发语言·golang·xcode
2401_863671357 天前
Go-ecc加密解密详解与代码_ecdsa
ios·golang·xcode
键盘敲没电7 天前
【iOS】MVC模式
ios·mvc·objective-c·xcode