iOS开发技巧iOS开发技术分享ios进阶酷

macOS Catalina 10.15 十分钟安装 Cocoa

2019-11-09  本文已影响0人  天空像天空一样蓝

由于之前电脑出现问题,被迫 格式化硬盘,所以电脑要重新配置

上图为敬

操作步骤

1、设置 ruby 源

Mac 系统自带的会安装好 ruby 环境

1.1、查看自己电脑的 ruby 源

ruby -v

ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

sudo gem update --system

1.2更换 ruby 镜像

gem sources -l
*** CURRENT SOURCES ***

https://rubygems.org/
gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
gem sources -a https://gems.ruby-china.com/
https://gems.ruby-china.com/ added to sources
gem sources -l
*** CURRENT SOURCES ***

https://gems.ruby-china.com/

2、安装 CocoaPods

ruby 环境安装后,就可以安装 CocoaPods 了

2.1、真假 CocoaPods

不要着急敲命令,往下看,有坑
不要着急敲命令,往下看,有坑
不要着急敲命令,往下看,有坑

方法一

sudo gem install cocoapods

等待了几分钟后,显示下面的信息,便表示已经安装成功了。

Installing ri documentation for cocoapods-1.8.4
Done installing documentation for thread_safe, tzinfo, concurrent-ruby, i18n, activesupport, nap, fuzzy_match, httpclient, algoliasearch, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, molinillo, atomos, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 21 seconds
29 gems installed
pod setup

可是,最怕的事情还是发生了,输入 pod setup 后什么也没有发生,不是说几百兆的文件等着我下载吗,难道5G真的这么快,NO,NO,NO,我并没有5G。

看到这里可以滑到底部看下 Alan的世界 的评论,原因是 CocoaPods 1.8将CDN切换为默认的规范回购源,并进行了一些增强!不在需要 git clone 去拉去庞大的master分支的所有代码,具体可以参考 http://blog.cocoapods.org/CocoaPods-1.8.0-beta/

此时,你的电脑上已经集成了 CocoaPods 并且能正常使用

下面我新建一个TestDemo ,集成AFNetworking

简单实验

方法二

sudo gem install -n /usr/local/bin cocoapods
Successfully installed cocoapods-1.8.4
Parsing documentation for cocoapods-1.8.4
Done installing documentation for cocoapods after 1 seconds
1 gem installed

纳尼,这么快,我不信

2.2、检测是否安装成功

pod search AFNetworking

pod search AFNetworking
[!] Unable to find a pod with name, author, summary, or description matching `AFNetworking`
git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master
Cloning into '/Users/gao/.cocoapods/repos/master'...
remote: Enumerating objects: 1130099, done.
remote: Total 1130099 (delta 0), reused 0 (delta 0)iB | 4.28 MiB/s
Receiving objects: 100% (1130099/1130099), 408.72 MiB | 2.84 MiB/s, done.
Resolving deltas: 100% (563214/563214), done.
Checking out files: 100% (141834/141834), done.

激动的心,颤抖的手,一个苹果没有吃完就 clone 好了,

pod search AFNetworking
Creating search index for spec repo 'master'.. Done!

第一次会出现上面的 Creating search index for spec repo 'master'.. 等到 出现 Done 后 就会出现我们搜索的结果,再次输入命令就不会出现这行代码了,直接就能搜索了。

pod search AFNetworking
[!] Unable to find a pod with name, author, summary, or description matching `AFNetworking`

-> AFNetworking (3.1.0)
   A delightful iOS and OS X networking framework.
   pod 'AFNetworking', '~> 3.1.0'
   - Homepage: https://github.com/AFNetworking/AFNetworking
   - Source:   https://github.com/AFNetworking/AFNetworking.git
   - Versions: 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-beta.3,
   3.0.0-beta.2, 3.0.0-beta.1, 2.6.3, 2.6.2, 2.6.1, 2.6.0, 2.5.4, 2.5.3, 2.5.2,
   2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0,
   2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4,
   1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2,
   1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]
   - Subspecs:
     - AFNetworking/Serialization (3.1.0)
     - AFNetworking/Security (3.1.0)
     - AFNetworking/Reachability (3.1.0)
     - AFNetworking/NSURLSession (3.1.0)
     - AFNetworking/UIKit (3.1.0)

-> AFNetworking+AutoRetry (0.0.5)
   Auto Retries for AFNetworking requests
   pod 'AFNetworking+AutoRetry', '~> 0.0.5'
   - Homepage: https://github.com/shaioz/AFNetworking-AutoRetry
   - Source:   https://github.com/shaioz/AFNetworking-AutoRetry.git
:

到此就代表 CocoaPods 真正安装成功喽。

3、使用 CocoaPods

文件目录

3.1、添加 Podfile 文件

cd 到文件目录

输入 touch Podfile 后,我们的工程目录中会出现 一个 Podfile 文件

添加 Podfile 文件

3.2、编辑 Podfile 文件

在文件中输入自己需要的第三方项目库,我们以 AFNetworking 为例

platform :ios, '10.0'

target 'CocoaPodsDemo' do

pod 'AFNetworking'

end

3.3、执行 pod

终端输入 pod install

pod install
Analyzing dependencies
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Downloading dependencies
Installing AFNetworking (3.2.1)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `CocoaPodsDemo.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

输出上面的内容就表示,已经成功了,提示我们关掉当前的看到上面的 项目,打开 CocoaPodsDemo.xcworkspace 这个项目,再次回到我们的项目目录里面查看,已经多了几个目录

目录 CocoaPods后项目结构

“人生哪能多如意,万事只求半称心”———最近挺喜欢这句话,分享给大家吧。

上一篇下一篇

猜你喜欢

热点阅读