GitLab构建自己的私有库
1.创建私有库工程
1)新建工程,选择Static Library,取名NicolasLibs


2)创建自己的文件,我创建一个打印类

2.在gitlab创建一个code repository(代码仓库), 一个spec repository(配置仓库)
还可以使用github(私有需要收费) 、开源中国、CODING、Bitbucket、CSDN code都可以3
1)在gitlab 点击+,创建代码仓库
注意:勾选生成readme.md文件,不然后面会push不了,当然可以后面创建

2)同样的步骤创建配置仓库(注意名字区分),最后得到两个私有仓库

3.使用SourceTree工具克隆两个仓库到本地,并把步骤1中代码提交到代码仓库,并打 tag
1)克隆两个仓库到本地:不知道怎么克隆的,自行百度哈

拉取后,别忘了执行gitlabe官方的一些命令,比如设置用户名与git账号等
2)将步骤1 代码,提交,并打tag

注意:勾选推送标签

4.创建和编辑三个文件
1)创建和编辑README.md、创建和编辑LICENSE
这个文件在github中也有,是项目的说明文件,根据自己的项目做一些说明.打开终端,cd到工具类文件所在的路径下

2)创建和编辑.podspec文件,这一步很关键
打开终端,输入 cd ~/ 命令
cd ~/
为了维护,建议名字跟工具类所在项目名一样,进入到根目录后创建一个名字叫NicolasLibs.podspec的文件
pod spec create NicolasLibs

使用vim进行编辑,或者直接使用记事本打开编辑(我选择后者)
vim NicolasLibs.podspec
清空,然后按下面的格式替换成你自己的私有库
Pod::Spec.new do |s|
s.name = "NicolasLibs"
s.version = "1.0.2" #当前版本
s.summary = "NicolasLibs a hello " #描述
s.homepage = "xxxxxx/Nicolas/nicolascoderep.git" #库文件主页地>址
s.license = 'MIT'
s.author = { '开发者名字' => '开发者账号' } #开发者
s.source = { :git => 'xxxxxxxxxx:Nicolas/nicolascoderep.git', :tag => s.version.to_s } #文件的git地址,以及当前版本对应的tag
s.source_files = 'NicolasLibs/NicolasLibs/*' #文件所在的目录,后面*是一个正则表达式,目录我下面会有解释
# s.source_files = 'NicolasLibs/NicolasLibs/*.{h,m}' #文件所在的目录,后面*.{h.m}是一个正则表达式,目录我下面会有解释
# s.resources = 'NicolasLibs/NicolasLibs/*.xib' #资源文件所在的目录图片,xib等,这个demo没有用到
s.framework = 'UIKit' #当前这个库所依赖的系统的库
s.platform = :ios,"9.0"
s.requires_arc = true #是否支持arc
s.swift_version = '5.0'
end
编辑完按Esc 并输入:wq下面的命令进行保存
:wq
3)进入终端进行验证,根目录
pod spec lint NicolasLibs.podspec --allow-warnings
出现passed validating则说明验证成功

5.创建本地的私有仓库文件
1)使用下面的命令就可以在本地生成配置文件的仓库,建议这个本地的名字也和远程的一致,这样便于区分和后期的维护.
NicolasSpecRep 是你远端创建的配置文件仓库的名字,后面是配置文件仓库远端的地址 .
注意:此时不需要cd进入任何目录,从默认位置输入这个命令,即在点击终端快捷方式打开的状态下直接输入下面的命令即可
pod repo add NicolasSpecRep https://xxxxx/Nicolas/nicolasspecrep.git
2)查看是否添加成功
pod repo list
如果出现NicolasSpecRep则说明添加成功

或者查看本地目录是否有NicolasSpecRep文件夹 (隐藏显示文件显示快捷键cmd+shift+.)

6.将配置文件push到远端的配置仓库
1)将配置文件push到远端专门存储配置文件的仓库中 ,本地的也会同步更新
此时需要cd进入本地的.podspec所在的路径,默认是根目录,否则会找不到podspec文件
使用下面的命令即可,有问题可以参考报错信息去修改
JXSpecRep 是你创建的spec repository配置仓库的名字,后面是你本地创建的.podspec文件
pod repo push NicolasSpecRep NicolasLibs.podspec --allow-warnings
出现下面信息则成功了

本地也会增加一个版本

3)云端也能查看到
7.确认制作完成并使用
1)查询是否有我们需要的私有库
pod search NicolasLibs
出现下图

2)新建一个测试项目,并初始化pod
pod init
编辑podfile 文件,使用vim或者直接用记事本笔记
source '..../Nicolas/nicolasspecrep.git' //远端配置仓库url
pod 'NicolasLibs'
3)cd 到测试工程根目录,执行pod install
pod install
inport导入并使用

8.更新
1)修改私有库代码,并提交远程仓库,并打新的tag
2)编辑.podspec 文件,修改成tag对应的版本
3)进入终端进行验证,根目录
pod spec lint NicolasLibs.podspec --allow-warnings
4)push推送到云端
pod repo push NicolasSpecRep NicolasLibs.podspec --allow-warnings
5)测试工程修改podfile中私有库版本,执行pod update 命令
pod update
后在执行
pod install
参考网上文章写的,如有疑问,欢迎留言