CocoasPods :强大的第三方库管理插件
直接合成到工程中,通过简单的pod 命令,实现三方资源库的下载跟新迭代管理。
关于CocoasPods 的安装和使用有许多文章, 这里给到其中一个连接 CocoasPod 及安装使用 here you are
Objective-C.gitignore: 在代码开发过程中进行版本控制,使用git的时候其实有一些文件是没有必要每次上传版本控制的,
githubgitignore是一个.gitignore的集合范本,这里对其使用也做简单介绍。
一、 CocoasPods安装使用资料整理
【第一步】 :查看自己电脑的Ruby环境
terminal 输入gem sources
1. 如果已经是淘宝镜像了【https://ruby.taobao.org/】直接进入【第二步】
2. 镜像处理, a. 如果不是,需要将当前的镜像移除:gem sources --remove https://ruby.taobao.org/
b. 紧接着使用淘宝镜像:gem sources -a https://ruby.taobao.org/
【第二步】:安装CocoasPods
1. 下载:sudo gem install cocoapods (这里等到terminal出现 **gems installed ,表示下载完成)
2. 设置:pod setup (这一步等到 Setup completed,表示设置完成,然后我们就可以使用了)
3. 查看进度, a. 如果需要查看设置的进度(下载量多,可以查看)方法见:
b. 新建一个terminal(command + n),进入到CocoasPods里(cd ~/cocoapods),查看进度:du -sh *
【第三步】:使用CocoasPods
1. 查找三方库文件:pod search + 第三方库名(支持默许匹配)
2. 可能会出现一堆列表,可选自己需要库的最新版本,例如:pod ‘MBProgressHUD’ , ~> 0.8
3. 如工程需要用到,可进入工程目录下(没有可创建工程XWCNDict为例):cd + 工程路径
4. 配置Podfile
a. 创建Podfile文件(vim Podfile),进入Podfile(输入字母 i 进入编辑状态),编辑Podfile内容如下:[输入结束后ESC退出编辑装填,shift+:让后输入wq保存编辑并退出]。-----------
platform :ios, ‘9.0‘
target "XWCNDict" do
pod 'FMDB', '~> 2.6'
end
b. 保存Podfile 设置,然后进行库下载或更新: pod install (pod update)。第一次成功下载后terminal会有提示,让使用.xcworkspace扩展名的文件打开工程。
【异常分析】:在使用过程中可能出现异常
1. terminal可能会报错:The dependency FMDB(~>2.6)is not used in any concrete target
原因是CocoasPods高级一些的版本中,Podfile 文件的内容必须明确指出所用第三方库的targeName,(target “targetName” do)
低版本:
platform :ios, ‘9.0‘
pod 'FMDB', '~> 2.6'
高版本:
platform :ios, ‘9.0‘
target "XWCNDict" do
pod 'FMDB', '~> 2.6'
end
2. 如果现在使用CocoasPods 建议使用如下方法:
a. 在当前工程目录下,执行命令 $ pod init 即可生成一个Podfile 文件,并且里头已经做了初始化文本,
b. 将需要添加的三方资源库添加到Podfile中 适当位置即可(最后一个end 之前的位置)
c. 安装命令可以使用 pod install --repo-update,能够更快一些,(pod install --help查看命令解释)
注意,--repo-update 之后不会对现有框架进行更新,所以速度快,如果框架升级,不能加上这个参数。
d. 这个方法中初始化文本看下面:注意 ‘#’号在这里的作用有 注释 的意思,
# platform :ios, '9.0'
# use_frameworks!
去掉前面的 # 符号,就表示三方库,会使准许后方的要求,如这里支持平台iOS,9 支持用户框架。
注意,Swift 做开发,同时又集成了CocoasPods,那么就需要打开框架use_frameworks(去掉#号)
下面这个大家伙(RAC) ,也需要将use_frameworks 前面的# 去掉,因为RAC本身也是支持Swift的。
ReactiveCocoa 点击打开链接 RAC here you are
下面这个就是 pod init 方法生成 Podfile的文本内容
---------------
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'sinofont' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for sinofont
end
target 'sinoTest' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for sinoTest
target 'sinoTestTests' do
inherit! :search_paths
# Pods for testing
end
end
---------------
【使用方法】
1. 到github上讲.gitignore 文件集合下载下来 (https://github.com/github/gitignore)
2. 打开gitignore-master 文件夹,里面有很多.gitignore 文件,找到其中的Objective-C.gitignore 文件,放到工程目录下。
3. 更改Objective-C.gitignore 文件名.gitignore (保留扩展名就好)。
注意,没有开启所有文件显示,上面在Finder中直接改名操作是无法完成的,接下里会知道:
在terminal中用命令修改:$ mv Objective-C.gitignore .gitignore 这样在finder中的.gitignore 文件是不可见的。
可以使用$ ls -laG /(ls -al )命令查看到Finder中的所有文件。
补充:
defaults write com.apple.finder AppleShowAllFiles -booleanfalse; //设置finder对隐藏文件的可见性 ,之后执行下句使设置生效。
killall Finder;//重启finder
【Pods文件处理】
1. 对于使用到CocoasPods的项目工程的版本管理,我们没有必要每次对Pods文件进行上传(消耗服务器空间,还有上传也要花时间的),可以做一下处理屏蔽Pods的每次提交(调整.gitignore文件)。
2. 处理方法:打开.gitignore文件,里头也有 # 符号,不过和Podfile中的不一样,它表示其对应的项目会全部被备份到git服务器上去。
3. 找到# CocoaPods那块,最下方有一个 # Pods,将前方的 # 去掉,表示 gitignore,Pods将不再被提交。
4. 如果进行了3 的做出,那么服务器上下来的工程将不会有Pods目录,需要自己在本地pod install。
下面这个就是.gitignore中的文本内容
----------
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xcuserstate
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
fastlane/report.xml
fastlane/screenshots
#Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
iOSInjectionProject/
补充:
除了Cocoapods之外,14年swift之后,另一个方便的工具叫做Carthage
如何使用Carthage管理iOS依赖库
参考文档,http://www.jianshu.com/p/5ccde5f22a17
------------