目的: 創建一個倉庫,存儲在本地,在本地的其他工程這種直接使用。
實現步驟如下
- 桌面創建文件夾:名字爲“cocoapods本地私有庫的使用”
- 然後文件夾裏創建文件夾:LocalLib文件夾,裏面創建文件夾TestPerson 文件夾裏再創建 Classes文件夾
- 然後 cd 進入Classes文件夾
- 執行終端命令: touch Person.h Person.m 創建這兩個文件
- LocalLib文件夾裏面創建一個名字爲test的Xcode項目
- 在TestPerson文件夾創建git
操作如下:可以參考git操作
cd /Users/liuxitong/Desktop/cocoapods本地私有庫的使用/LocalLib/TestPerson
git init
git add .
git commit -m 'x'
- 然後創建spec文件:
pod spec create TestPerson
- 修改 testPerson.podspec 文件的內容
Pod::Spec.new do |spec|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
spec.name = "testPerson"
spec.version = "0.0.1"
spec.summary = "testPerson."
# This description is used to generate tags and improve search results.
spec.description = "testPerson.xxx"
spec.homepage = "http://EXAMPLE/testPerson"
# spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
spec.license = "MIT"
# spec.license = { :type => "MIT", :file => "FILE_LICENSE" }
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
#
spec.author = { "liyunxiang" => "[email protected]" }
# Or just: spec.author = "liyunxiang"
# spec.authors = { "liyunxiang" => "[email protected]" }
# spec.social_media_url = "https://twitter.com/liyunxiang"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
# 本地庫的話這裏git 設置成空的即可
spec.source = { :git => "", :tag => "#{spec.version}" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
# "Classes", "Classes/**/*.{h,m}"代表Classes文件,以及該文件裏面的‘/**’所有文件夾裏面的.h 、.m文件
spec.source_files = "Classes", "Classes/**/*.{h,m}"
#spec.exclude_files = "Classes/Exclude"
# spec.public_header_files = "Classes/**/*.h"
end
現在相當於完成了本地私有庫
- test工程裏面安裝剛纔的testPerson私有庫
- 給現在test工程集成pod
cd /Users/liuxitong/Desktop/cocoapods本地私有庫的使用/LocalLib/test
pod init
創建podfile文件- 然後編輯podfile文件
# platform :ios, '9.0'
target 'test' do
use_frameworks!
# 代表,到時候會尋找,會到某個路徑下下面,找一個文件testPerson.podspec
# 如果是本地庫纔會使用path=> '../testPerson'
#如果是遠程的話,就不需要了,終端pod repo可以看到有pod的默認的URL路徑,如下
#master
#- Type: git (master)
#- URL: https://github.com/CocoaPods/Specs.git
#- Path: /Users/liuxitong/.cocoapods/repos/master
pod 'testPerson', :path=> '../testPerson'
end
- 然後cd 進test工程
- 執行
pod install
- 執行效果如圖所示:
上文說到的文件夾的最終整體路徑展示:
test項目集成pod以後,工程裏面的路徑以及文件展示:
因爲是做得本地私有庫,所以會放在這個文件夾裏面,正常的遠程的是放在Pods裏面的Pods文件夾,如圖所示: