iOS創建Cocoapods私有庫

一、創建私有的Spec Repo(git倉庫1)

二、創建Pod項目工程,并且又可以訪問的項目版本控制地址(git倉庫2)

三、創建并提交MyLib Pod庫的podspec文件到私有Spec Repo倉庫

四、使用制作好的Pod

一、創建私有的Spec Repo

Spec Repo 是所有的Pods的一個索引,是所有公開的Pods 的podspec 文件的一個倉庫,其實就是一個部署在服務器的Git倉庫,當你使用CocoaPods 后它會被Clone到本地的 ~/.cocoapods/repos 目錄下,大概的文件目錄如下:


qEPQ3.png

Tip:~/.cocoapods/repos文件是一個隱藏目錄,在Mac 上默認是看不到隱藏目錄的,但是我們可以通過「終端」應用程序打開。在Terminal中執行以下命令顯示隱藏文件:

$ defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder 

執行以下命令恢復隱藏文件:

$ defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder 

上文的目錄樹形圖就是我電腦的本地的 ~/.cocoapods/repos目錄,其中master就是官方的Sepc Repo,跟master同目錄級別的BlueCloudSpecs目錄就是我自己的創建的私有Sepc Repo。

*首先在github上創建一個MySpecs項目,如果是公司的私有庫當然是在公司的gitLab上面創建。


qEEJE.jpg

*在終端執行以下命令。


qEncr.jpg

注意:這個Git 倉庫地址要換成你自己的創建的 Specs git 地址!!!
成功后會在~/.cocoapods/repos目錄下就能看到MySpecs了,至此,第一步創建私有

Spec Repo就完成了。


WX20180718-010057.png

二、創建Pod項目工程

1.創建Pod項目工程
首先,在coding.net上創建一個github項目,當然你也是可以在公司內網創建的。
然后,使用Cocoapods提供的一個Using Pod Lib Create 工具創建一個工程。
在Terminal中執行cd進入要創建項目的目錄然后 執行以下命令:


WX20180719-004443.png

接著在Terminal控制臺會輸出:


WechatIMG135.jpeg

第一個問題是問你選擇iOS還是macOS平臺。此教程選的是iOS。
WX20180719-005628.png

第二個問題是問你選擇Swift還是Objc構建項目。此教程 選的是ObjC
WX20180719-005840.png

第三個問題問你是否需要創建一個Demo項目,此教程選的是Yes
WX20180719-010316.png

第四個問題讓你是否選擇一個測試框架,此教程選 Specta


WX20180719-010749.png

第五個問題是否基于View測試,選Yes
WX20180721-104017@2x.png

第六個問題是詢問 類的前綴,設為BC
設置完成后自動打開Xcode并控制臺輸出如下:
WX20180721-105104@2x.png

成功后會在目錄中創建好一個BCAlertView工程,結構(查看當前目錄結構直接在終端輸入tree,若沒有安裝tree,則輸入brew install tree進行安裝)如下:
WX20180721-143703@2x.png

Snip20180721_5.png

Snip20180721_6.png
├── BCAlertView
│   ├── Assets
│   └── Classes
│       └── ReplaceMe.m   **注意存放你自己實現的庫相關代碼!!!**
├── BCAlertView.podspec    ** 庫的podspec文件,這個是下一步需要重點配置的文件 !!!**
├── Example
│   ├── BCAlertView
│   │   ├── BCAlertView-Info.plist
│   │   ├── BCAlertView-Prefix.pch
│   │   ├── BCAppDelegate.h
│   │   ├── BCAppDelegate.m
│   │   ├── BCViewController.h
│   │   ├── BCViewController.m
│   │   ├── Base.lproj
│   │   │   ├── LaunchScreen.storyboard
│   │   │   └── Main.storyboard
│   │   ├── Images.xcassets
│   │   │   └── AppIcon.appiconset
│   │   │       └── Contents.json
│   │   ├── en.lproj
│   │   │   └── InfoPlist.strings
│   │   └── main.m
│   ├── BCAlertView.xcodeproj
│   │   ├── project.pbxproj
│   │   ├── project.xcworkspace
│   │   │   └── contents.xcworkspacedata
│   │   └── xcshareddata
│   │       └── xcschemes
│   │           └── BCAlertView-Example.xcscheme
│   ├── BCAlertView.xcworkspace
│   │   ├── contents.xcworkspacedata
│   │   └── xcuserdata
│   │       └── cloud.xcuserdatad
│   │           └── UserInterfaceState.xcuserstate
│   ├── Podfile
│   ├── Podfile.lock
│   ├── Pods
│   │   ├── Expecta
│   │   │   ├── Expecta
│   │   │   │   ├── EXPBlockDefinedMatcher.h
│   │   │   │   ├── EXPBlockDefinedMatcher.m
│   │   │   │   ├── EXPDefines.h
│   │   │   │   ├── EXPDoubleTuple.h
│   │   │   │   ├── EXPDoubleTuple.m
│   │   │   │   ├── EXPExpect.h
│   │   │   │   ├── EXPExpect.m
│   │   │   │   ├── EXPFloatTuple.h
│   │   │   │   ├── EXPFloatTuple.m
│   │   │   │   ├── EXPMatcher.h
│   │   │   │   ├── EXPUnsupportedObject.h
│   │   │   │   ├── EXPUnsupportedObject.m
│   │   │   │   ├── Expecta.h
│   │   │   │   ├── ExpectaObject.h
│   │   │   │   ├── ExpectaObject.m
│   │   │   │   ├── ExpectaSupport.h
│   │   │   │   ├── ExpectaSupport.m
│   │   │   │   ├── Matchers
│   │   │   │   │   ├── EXPMatcherHelpers.h
│   │   │   │   │   ├── EXPMatcherHelpers.m
│   │   │   │   │   ├── EXPMatchers+beCloseTo.h
│   │   │   │   │   ├── EXPMatchers+beCloseTo.m
│   │   │   │   │   ├── EXPMatchers+beFalsy.h
│   │   │   │   │   ├── EXPMatchers+beFalsy.m
│   │   │   │   │   ├── EXPMatchers+beGreaterThan.h
│   │   │   │   │   ├── EXPMatchers+beGreaterThan.m
│   │   │   │   │   ├── EXPMatchers+beGreaterThanOrEqualTo.h
│   │   │   │   │   ├── EXPMatchers+beGreaterThanOrEqualTo.m
│   │   │   │   │   ├── EXPMatchers+beIdenticalTo.h
│   │   │   │   │   ├── EXPMatchers+beIdenticalTo.m
│   │   │   │   │   ├── EXPMatchers+beInTheRangeOf.h
│   │   │   │   │   ├── EXPMatchers+beInTheRangeOf.m
│   │   │   │   │   ├── EXPMatchers+beInstanceOf.h
│   │   │   │   │   ├── EXPMatchers+beInstanceOf.m
│   │   │   │   │   ├── EXPMatchers+beKindOf.h
│   │   │   │   │   ├── EXPMatchers+beKindOf.m
│   │   │   │   │   ├── EXPMatchers+beLessThan.h
│   │   │   │   │   ├── EXPMatchers+beLessThan.m
│   │   │   │   │   ├── EXPMatchers+beLessThanOrEqualTo.h
│   │   │   │   │   ├── EXPMatchers+beLessThanOrEqualTo.m
│   │   │   │   │   ├── EXPMatchers+beNil.h
│   │   │   │   │   ├── EXPMatchers+beNil.m
│   │   │   │   │   ├── EXPMatchers+beSubclassOf.h
│   │   │   │   │   ├── EXPMatchers+beSubclassOf.m
│   │   │   │   │   ├── EXPMatchers+beSupersetOf.h
│   │   │   │   │   ├── EXPMatchers+beSupersetOf.m
│   │   │   │   │   ├── EXPMatchers+beTruthy.h
│   │   │   │   │   ├── EXPMatchers+beTruthy.m
│   │   │   │   │   ├── EXPMatchers+beginWith.h
│   │   │   │   │   ├── EXPMatchers+beginWith.m
│   │   │   │   │   ├── EXPMatchers+conformTo.h
│   │   │   │   │   ├── EXPMatchers+conformTo.m
│   │   │   │   │   ├── EXPMatchers+contain.h
│   │   │   │   │   ├── EXPMatchers+contain.m
│   │   │   │   │   ├── EXPMatchers+endWith.h
│   │   │   │   │   ├── EXPMatchers+endWith.m
│   │   │   │   │   ├── EXPMatchers+equal.h
│   │   │   │   │   ├── EXPMatchers+equal.m
│   │   │   │   │   ├── EXPMatchers+haveCountOf.h
│   │   │   │   │   ├── EXPMatchers+haveCountOf.m
│   │   │   │   │   ├── EXPMatchers+match.h
│   │   │   │   │   ├── EXPMatchers+match.m
│   │   │   │   │   ├── EXPMatchers+postNotification.h
│   │   │   │   │   ├── EXPMatchers+postNotification.m
│   │   │   │   │   ├── EXPMatchers+raise.h
│   │   │   │   │   ├── EXPMatchers+raise.m
│   │   │   │   │   ├── EXPMatchers+raiseWithReason.h
│   │   │   │   │   ├── EXPMatchers+raiseWithReason.m
│   │   │   │   │   ├── EXPMatchers+respondTo.h
│   │   │   │   │   ├── EXPMatchers+respondTo.m
│   │   │   │   │   └── EXPMatchers.h
│   │   │   │   ├── NSObject+Expecta.h
│   │   │   │   ├── NSValue+Expecta.h
│   │   │   │   └── NSValue+Expecta.m
│   │   │   ├── LICENSE
│   │   │   └── README.md
│   │   ├── Expecta+Snapshots
│   │   │   ├── EXPMatchers+FBSnapshotTest.h
│   │   │   ├── EXPMatchers+FBSnapshotTest.m
│   │   │   ├── ExpectaObject+FBSnapshotTest.h
│   │   │   ├── ExpectaObject+FBSnapshotTest.m
│   │   │   ├── LICENSE.md
│   │   │   └── README.md
│   │   ├── FBSnapshotTestCase
│   │   │   ├── FBSnapshotTestCase
│   │   │   │   ├── Categories
│   │   │   │   │   ├── UIApplication+StrictKeyWindow.h
│   │   │   │   │   ├── UIApplication+StrictKeyWindow.m
│   │   │   │   │   ├── UIImage+Compare.h
│   │   │   │   │   ├── UIImage+Compare.m
│   │   │   │   │   ├── UIImage+Diff.h
│   │   │   │   │   ├── UIImage+Diff.m
│   │   │   │   │   ├── UIImage+Snapshot.h
│   │   │   │   │   └── UIImage+Snapshot.m
│   │   │   │   ├── FBSnapshotTestCase.h
│   │   │   │   ├── FBSnapshotTestCase.m
│   │   │   │   ├── FBSnapshotTestCasePlatform.h
│   │   │   │   ├── FBSnapshotTestCasePlatform.m
│   │   │   │   ├── FBSnapshotTestController.h
│   │   │   │   ├── FBSnapshotTestController.m
│   │   │   │   └── SwiftSupport.swift
│   │   │   ├── LICENSE
│   │   │   └── README.md
│   │   ├── Headers
│   │   ├── Local\ Podspecs
│   │   │   └── BCAlertView.podspec.json
│   │   ├── Manifest.lock
│   │   ├── Pods.xcodeproj
│   │   │   ├── project.pbxproj
│   │   │   └── xcuserdata
│   │   │       └── cloud.xcuserdatad
│   │   │           └── xcschemes
│   │   │               ├── BCAlertView.xcscheme
│   │   │               ├── Expecta+Snapshots.xcscheme
│   │   │               ├── Expecta.xcscheme
│   │   │               ├── FBSnapshotTestCase.xcscheme
│   │   │               ├── Pods-BCAlertView_Example.xcscheme
│   │   │               ├── Pods-BCAlertView_Tests.xcscheme
│   │   │               ├── Specta.xcscheme
│   │   │               └── xcschememanagement.plist
│   │   ├── Specta
│   │   │   ├── LICENSE
│   │   │   ├── README.md
│   │   │   └── Specta
│   │   │       └── Specta
│   │   │           ├── SPTCallSite.h
│   │   │           ├── SPTCallSite.m
│   │   │           ├── SPTCompiledExample.h
│   │   │           ├── SPTCompiledExample.m
│   │   │           ├── SPTExample.h
│   │   │           ├── SPTExample.m
│   │   │           ├── SPTExampleGroup.h
│   │   │           ├── SPTExampleGroup.m
│   │   │           ├── SPTExcludeGlobalBeforeAfterEach.h
│   │   │           ├── SPTGlobalBeforeAfterEach.h
│   │   │           ├── SPTSharedExampleGroups.h
│   │   │           ├── SPTSharedExampleGroups.m
│   │   │           ├── SPTSpec.h
│   │   │           ├── SPTSpec.m
│   │   │           ├── SPTTestSuite.h
│   │   │           ├── SPTTestSuite.m
│   │   │           ├── Specta.h
│   │   │           ├── SpectaDSL.h
│   │   │           ├── SpectaDSL.m
│   │   │           ├── SpectaTypes.h
│   │   │           ├── SpectaUtility.h
│   │   │           ├── SpectaUtility.m
│   │   │           ├── XCTest+Private.h
│   │   │           ├── XCTestCase+Specta.h
│   │   │           └── XCTestCase+Specta.m
│   │   └── Target\ Support\ Files
│   │       ├── BCAlertView
│   │       │   ├── BCAlertView-dummy.m
│   │       │   ├── BCAlertView-prefix.pch
│   │       │   ├── BCAlertView-umbrella.h
│   │       │   ├── BCAlertView.modulemap
│   │       │   ├── BCAlertView.xcconfig
│   │       │   └── Info.plist
│   │       ├── Expecta
│   │       │   ├── Expecta-dummy.m
│   │       │   ├── Expecta-prefix.pch
│   │       │   ├── Expecta-umbrella.h
│   │       │   ├── Expecta.modulemap
│   │       │   ├── Expecta.xcconfig
│   │       │   └── Info.plist
│   │       ├── Expecta+Snapshots
│   │       │   ├── Expecta+Snapshots-dummy.m
│   │       │   ├── Expecta+Snapshots-prefix.pch
│   │       │   ├── Expecta+Snapshots-umbrella.h
│   │       │   ├── Expecta+Snapshots.modulemap
│   │       │   ├── Expecta+Snapshots.xcconfig
│   │       │   └── Info.plist
│   │       ├── FBSnapshotTestCase
│   │       │   ├── FBSnapshotTestCase-dummy.m
│   │       │   ├── FBSnapshotTestCase-prefix.pch
│   │       │   ├── FBSnapshotTestCase-umbrella.h
│   │       │   ├── FBSnapshotTestCase.modulemap
│   │       │   ├── FBSnapshotTestCase.xcconfig
│   │       │   └── Info.plist
│   │       ├── Pods-BCAlertView_Example
│   │       │   ├── Info.plist
│   │       │   ├── Pods-BCAlertView_Example-acknowledgements.markdown
│   │       │   ├── Pods-BCAlertView_Example-acknowledgements.plist
│   │       │   ├── Pods-BCAlertView_Example-dummy.m
│   │       │   ├── Pods-BCAlertView_Example-frameworks.sh
│   │       │   ├── Pods-BCAlertView_Example-resources.sh
│   │       │   ├── Pods-BCAlertView_Example-umbrella.h
│   │       │   ├── Pods-BCAlertView_Example.debug.xcconfig
│   │       │   ├── Pods-BCAlertView_Example.modulemap
│   │       │   └── Pods-BCAlertView_Example.release.xcconfig
│   │       ├── Pods-BCAlertView_Tests
│   │       │   ├── Info.plist
│   │       │   ├── Pods-BCAlertView_Tests-acknowledgements.markdown
│   │       │   ├── Pods-BCAlertView_Tests-acknowledgements.plist
│   │       │   ├── Pods-BCAlertView_Tests-dummy.m
│   │       │   ├── Pods-BCAlertView_Tests-frameworks.sh
│   │       │   ├── Pods-BCAlertView_Tests-resources.sh
│   │       │   ├── Pods-BCAlertView_Tests-umbrella.h
│   │       │   ├── Pods-BCAlertView_Tests.debug.xcconfig
│   │       │   ├── Pods-BCAlertView_Tests.modulemap
│   │       │   └── Pods-BCAlertView_Tests.release.xcconfig
│   │       └── Specta
│   │           ├── Info.plist
│   │           ├── Specta-dummy.m
│   │           ├── Specta-prefix.pch
│   │           ├── Specta-umbrella.h
│   │           ├── Specta.modulemap
│   │           └── Specta.xcconfig
│   └── Tests
│       ├── Tests-Info.plist
│       ├── Tests-Prefix.pch
│       ├── Tests.m
│       └── en.lproj
│           └── InfoPlist.strings
├── LICENSE
├── README.md
└── _Pods.xcodeproj -> Example/Pods/Pods.xcodeproj

2.添加實現代碼

├── BCAlertView
│   ├── Assets
│   └── Classes
│       └── ReplaceMe.m **注意存放你自己實現的庫相關代碼!!!**

在本教程中我在上面的Classes文件目錄添加了BCAlertView.h、BCAlertView.m兩個文件。現在目錄結構如下:

.
├── BCAlertView
│   ├── Assets
│   └── Classes
│       ├── BCAlertView.h
│       ├── BCAlertView.m
│       └── ReplaceMe.m
├── BCAlertView.podspec
├── Example
│   ├── BCAlertView
│   │   ├── BCAlertView-Info.plist
│   │   ├── BCAlertView-Prefix.pch
│   │   ├── BCAppDelegate.h
│   │   ├── BCAppDelegate.m
│   │   ├── BCViewController.h
│   │   ├── BCViewController.m
│   │   ├── Base.lproj
│   │   │   ├── LaunchScreen.storyboard
│   │   │   └── Main.storyboard
│   │   ├── Images.xcassets
│   │   │   └── AppIcon.appiconset
│   │   │       └── Contents.json
│   │   ├── en.lproj
│   │   │   └── InfoPlist.strings
│   │   └── main.m
│   ├── BCAlertView.xcodeproj
│   │   ├── project.pbxproj
│   │   ├── project.xcworkspace
│   │   │   └── contents.xcworkspacedata
│   │   └── xcshareddata
│   │       └── xcschemes
│   │           └── BCAlertView-Example.xcscheme
│   ├── BCAlertView.xcworkspace
│   │   ├── contents.xcworkspacedata
│   │   └── xcuserdata
│   │       └── cloud.xcuserdatad
│   │           └── UserInterfaceState.xcuserstate
│   ├── Podfile
│   ├── Podfile.lock
│   ├── Pods
│   │   ├── Expecta
│   │   │   ├── Expecta
│   │   │   │   ├── EXPBlockDefinedMatcher.h
│   │   │   │   ├── EXPBlockDefinedMatcher.m
│   │   │   │   ├── EXPDefines.h
│   │   │   │   ├── EXPDoubleTuple.h
│   │   │   │   ├── EXPDoubleTuple.m
│   │   │   │   ├── EXPExpect.h
│   │   │   │   ├── EXPExpect.m
│   │   │   │   ├── EXPFloatTuple.h
│   │   │   │   ├── EXPFloatTuple.m
│   │   │   │   ├── EXPMatcher.h
│   │   │   │   ├── EXPUnsupportedObject.h
│   │   │   │   ├── EXPUnsupportedObject.m
│   │   │   │   ├── Expecta.h
│   │   │   │   ├── ExpectaObject.h
│   │   │   │   ├── ExpectaObject.m
│   │   │   │   ├── ExpectaSupport.h
│   │   │   │   ├── ExpectaSupport.m
│   │   │   │   ├── Matchers
│   │   │   │   │   ├── EXPMatcherHelpers.h
│   │   │   │   │   ├── EXPMatcherHelpers.m
│   │   │   │   │   ├── EXPMatchers+beCloseTo.h
│   │   │   │   │   ├── EXPMatchers+beCloseTo.m
│   │   │   │   │   ├── EXPMatchers+beFalsy.h
│   │   │   │   │   ├── EXPMatchers+beFalsy.m
│   │   │   │   │   ├── EXPMatchers+beGreaterThan.h
│   │   │   │   │   ├── EXPMatchers+beGreaterThan.m
│   │   │   │   │   ├── EXPMatchers+beGreaterThanOrEqualTo.h
│   │   │   │   │   ├── EXPMatchers+beGreaterThanOrEqualTo.m
│   │   │   │   │   ├── EXPMatchers+beIdenticalTo.h
│   │   │   │   │   ├── EXPMatchers+beIdenticalTo.m
│   │   │   │   │   ├── EXPMatchers+beInTheRangeOf.h
│   │   │   │   │   ├── EXPMatchers+beInTheRangeOf.m
│   │   │   │   │   ├── EXPMatchers+beInstanceOf.h
│   │   │   │   │   ├── EXPMatchers+beInstanceOf.m
│   │   │   │   │   ├── EXPMatchers+beKindOf.h
│   │   │   │   │   ├── EXPMatchers+beKindOf.m
│   │   │   │   │   ├── EXPMatchers+beLessThan.h
│   │   │   │   │   ├── EXPMatchers+beLessThan.m
│   │   │   │   │   ├── EXPMatchers+beLessThanOrEqualTo.h
│   │   │   │   │   ├── EXPMatchers+beLessThanOrEqualTo.m
│   │   │   │   │   ├── EXPMatchers+beNil.h
│   │   │   │   │   ├── EXPMatchers+beNil.m
│   │   │   │   │   ├── EXPMatchers+beSubclassOf.h
│   │   │   │   │   ├── EXPMatchers+beSubclassOf.m
│   │   │   │   │   ├── EXPMatchers+beSupersetOf.h
│   │   │   │   │   ├── EXPMatchers+beSupersetOf.m
│   │   │   │   │   ├── EXPMatchers+beTruthy.h
│   │   │   │   │   ├── EXPMatchers+beTruthy.m
│   │   │   │   │   ├── EXPMatchers+beginWith.h
│   │   │   │   │   ├── EXPMatchers+beginWith.m
│   │   │   │   │   ├── EXPMatchers+conformTo.h
│   │   │   │   │   ├── EXPMatchers+conformTo.m
│   │   │   │   │   ├── EXPMatchers+contain.h
│   │   │   │   │   ├── EXPMatchers+contain.m
│   │   │   │   │   ├── EXPMatchers+endWith.h
│   │   │   │   │   ├── EXPMatchers+endWith.m
│   │   │   │   │   ├── EXPMatchers+equal.h
│   │   │   │   │   ├── EXPMatchers+equal.m
│   │   │   │   │   ├── EXPMatchers+haveCountOf.h
│   │   │   │   │   ├── EXPMatchers+haveCountOf.m
│   │   │   │   │   ├── EXPMatchers+match.h
│   │   │   │   │   ├── EXPMatchers+match.m
│   │   │   │   │   ├── EXPMatchers+postNotification.h
│   │   │   │   │   ├── EXPMatchers+postNotification.m
│   │   │   │   │   ├── EXPMatchers+raise.h
│   │   │   │   │   ├── EXPMatchers+raise.m
│   │   │   │   │   ├── EXPMatchers+raiseWithReason.h
│   │   │   │   │   ├── EXPMatchers+raiseWithReason.m
│   │   │   │   │   ├── EXPMatchers+respondTo.h
│   │   │   │   │   ├── EXPMatchers+respondTo.m
│   │   │   │   │   └── EXPMatchers.h
│   │   │   │   ├── NSObject+Expecta.h
│   │   │   │   ├── NSValue+Expecta.h
│   │   │   │   └── NSValue+Expecta.m
│   │   │   ├── LICENSE
│   │   │   └── README.md
│   │   ├── Expecta+Snapshots
│   │   │   ├── EXPMatchers+FBSnapshotTest.h
│   │   │   ├── EXPMatchers+FBSnapshotTest.m
│   │   │   ├── ExpectaObject+FBSnapshotTest.h
│   │   │   ├── ExpectaObject+FBSnapshotTest.m
│   │   │   ├── LICENSE.md
│   │   │   └── README.md
│   │   ├── FBSnapshotTestCase
│   │   │   ├── FBSnapshotTestCase
│   │   │   │   ├── Categories
│   │   │   │   │   ├── UIApplication+StrictKeyWindow.h
│   │   │   │   │   ├── UIApplication+StrictKeyWindow.m
│   │   │   │   │   ├── UIImage+Compare.h
│   │   │   │   │   ├── UIImage+Compare.m
│   │   │   │   │   ├── UIImage+Diff.h
│   │   │   │   │   ├── UIImage+Diff.m
│   │   │   │   │   ├── UIImage+Snapshot.h
│   │   │   │   │   └── UIImage+Snapshot.m
│   │   │   │   ├── FBSnapshotTestCase.h
│   │   │   │   ├── FBSnapshotTestCase.m
│   │   │   │   ├── FBSnapshotTestCasePlatform.h
│   │   │   │   ├── FBSnapshotTestCasePlatform.m
│   │   │   │   ├── FBSnapshotTestController.h
│   │   │   │   ├── FBSnapshotTestController.m
│   │   │   │   └── SwiftSupport.swift
│   │   │   ├── LICENSE
│   │   │   └── README.md
│   │   ├── Headers
│   │   ├── Local\ Podspecs
│   │   │   └── BCAlertView.podspec.json
│   │   ├── Manifest.lock
│   │   ├── Pods.xcodeproj
│   │   │   ├── project.pbxproj
│   │   │   └── xcuserdata
│   │   │       └── cloud.xcuserdatad
│   │   │           └── xcschemes
│   │   │               ├── BCAlertView.xcscheme
│   │   │               ├── Expecta+Snapshots.xcscheme
│   │   │               ├── Expecta.xcscheme
│   │   │               ├── FBSnapshotTestCase.xcscheme
│   │   │               ├── Pods-BCAlertView_Example.xcscheme
│   │   │               ├── Pods-BCAlertView_Tests.xcscheme
│   │   │               ├── Specta.xcscheme
│   │   │               └── xcschememanagement.plist
│   │   ├── Specta
│   │   │   ├── LICENSE
│   │   │   ├── README.md
│   │   │   └── Specta
│   │   │       └── Specta
│   │   │           ├── SPTCallSite.h
│   │   │           ├── SPTCallSite.m
│   │   │           ├── SPTCompiledExample.h
│   │   │           ├── SPTCompiledExample.m
│   │   │           ├── SPTExample.h
│   │   │           ├── SPTExample.m
│   │   │           ├── SPTExampleGroup.h
│   │   │           ├── SPTExampleGroup.m
│   │   │           ├── SPTExcludeGlobalBeforeAfterEach.h
│   │   │           ├── SPTGlobalBeforeAfterEach.h
│   │   │           ├── SPTSharedExampleGroups.h
│   │   │           ├── SPTSharedExampleGroups.m
│   │   │           ├── SPTSpec.h
│   │   │           ├── SPTSpec.m
│   │   │           ├── SPTTestSuite.h
│   │   │           ├── SPTTestSuite.m
│   │   │           ├── Specta.h
│   │   │           ├── SpectaDSL.h
│   │   │           ├── SpectaDSL.m
│   │   │           ├── SpectaTypes.h
│   │   │           ├── SpectaUtility.h
│   │   │           ├── SpectaUtility.m
│   │   │           ├── XCTest+Private.h
│   │   │           ├── XCTestCase+Specta.h
│   │   │           └── XCTestCase+Specta.m
│   │   └── Target\ Support\ Files
│   │       ├── BCAlertView
│   │       │   ├── BCAlertView-dummy.m
│   │       │   ├── BCAlertView-prefix.pch
│   │       │   ├── BCAlertView-umbrella.h
│   │       │   ├── BCAlertView.modulemap
│   │       │   ├── BCAlertView.xcconfig
│   │       │   └── Info.plist
│   │       ├── Expecta
│   │       │   ├── Expecta-dummy.m
│   │       │   ├── Expecta-prefix.pch
│   │       │   ├── Expecta-umbrella.h
│   │       │   ├── Expecta.modulemap
│   │       │   ├── Expecta.xcconfig
│   │       │   └── Info.plist
│   │       ├── Expecta+Snapshots
│   │       │   ├── Expecta+Snapshots-dummy.m
│   │       │   ├── Expecta+Snapshots-prefix.pch
│   │       │   ├── Expecta+Snapshots-umbrella.h
│   │       │   ├── Expecta+Snapshots.modulemap
│   │       │   ├── Expecta+Snapshots.xcconfig
│   │       │   └── Info.plist
│   │       ├── FBSnapshotTestCase
│   │       │   ├── FBSnapshotTestCase-dummy.m
│   │       │   ├── FBSnapshotTestCase-prefix.pch
│   │       │   ├── FBSnapshotTestCase-umbrella.h
│   │       │   ├── FBSnapshotTestCase.modulemap
│   │       │   ├── FBSnapshotTestCase.xcconfig
│   │       │   └── Info.plist
│   │       ├── Pods-BCAlertView_Example
│   │       │   ├── Info.plist
│   │       │   ├── Pods-BCAlertView_Example-acknowledgements.markdown
│   │       │   ├── Pods-BCAlertView_Example-acknowledgements.plist
│   │       │   ├── Pods-BCAlertView_Example-dummy.m
│   │       │   ├── Pods-BCAlertView_Example-frameworks.sh
│   │       │   ├── Pods-BCAlertView_Example-resources.sh
│   │       │   ├── Pods-BCAlertView_Example-umbrella.h
│   │       │   ├── Pods-BCAlertView_Example.debug.xcconfig
│   │       │   ├── Pods-BCAlertView_Example.modulemap
│   │       │   └── Pods-BCAlertView_Example.release.xcconfig
│   │       ├── Pods-BCAlertView_Tests
│   │       │   ├── Info.plist
│   │       │   ├── Pods-BCAlertView_Tests-acknowledgements.markdown
│   │       │   ├── Pods-BCAlertView_Tests-acknowledgements.plist
│   │       │   ├── Pods-BCAlertView_Tests-dummy.m
│   │       │   ├── Pods-BCAlertView_Tests-frameworks.sh
│   │       │   ├── Pods-BCAlertView_Tests-resources.sh
│   │       │   ├── Pods-BCAlertView_Tests-umbrella.h
│   │       │   ├── Pods-BCAlertView_Tests.debug.xcconfig
│   │       │   ├── Pods-BCAlertView_Tests.modulemap
│   │       │   └── Pods-BCAlertView_Tests.release.xcconfig
│   │       └── Specta
│   │           ├── Info.plist
│   │           ├── Specta-dummy.m
│   │           ├── Specta-prefix.pch
│   │           ├── Specta-umbrella.h
│   │           ├── Specta.modulemap
│   │           └── Specta.xcconfig
│   └── Tests
│       ├── Tests-Info.plist
│       ├── Tests-Prefix.pch
│       ├── Tests.m
│       └── en.lproj
│           └── InfoPlist.strings
├── LICENSE
├── README.md
└── _Pods.xcodeproj -> Example/Pods/Pods.xcodeproj

3.開發模式下測試pod庫的代碼
打開Example工程目錄Podfile文件

use_frameworks!

target 'BCAlertView_Example' do
  pod 'BCAlertView', :path => '../' //指定路徑
  #pod 'BCAlertView', :podspec => '../BCAlertView.podspec'  # 指定podspec文件
  target 'BCAlertView_Tests' do
    inherit! :search_paths

    pod 'Specta'
    pod 'Expecta'
    pod 'FBSnapshotTestCase'
    pod 'Expecta+Snapshots'
  end
end

然后在Example工程目錄下執行 pod update命令安裝依賴

WX20180721-164306@2x.png

打開項目工程,可以看到庫文件都被加載到Pods子項目中了。

不過它們并沒有在Pods目錄下,而是跟測試項目一樣存在于Development Pods/BCAlertView中,這是因為我們是在本地測試,而沒有把podspec文件添加到Spec Repo中的緣故。測試庫文件沒有問題,接著我們需要執行第4步

WX20180721-163642@2x.png

4.提交Pod庫到Git倉庫2

在Terminal中執行 cd進入BCAlertView項目根目錄然后,執行以下命令:

$ git add .
$ git commit -s -m "初始化BCAlertView庫"
$ git remote add origin https://github.com/yanyi0/BCAlertView.git   #添加遠端倉庫
$ git push origin master     #提交到遠端倉庫
$ git tag -m "first release" "0.0.1" #打上標簽,這個很重要
$ git push --tags     #推送tag到遠端倉庫
WX20180721-170132@2x.png

WX20180721-170815@2x.png

到這里,成功提交到遠程 Git倉庫2,BCAlertView Pod庫就初步完成了代碼實現。

三、創建并提交MyLibPod庫的podspec文件到私有Spec Repo倉庫

1.配置BCAlertView庫的podspec 文件

#
# Be sure to run `pod lib lint BCAlertView.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  #名稱
  s.name             = 'BCAlertView'
  #版本號
  s.version          = '0.0.1'
  #簡介
  s.summary          = 'A short description of BCAlertView.'

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!
  #描述     
  s.description      = '熱更新彈窗,更新帶進度條漸變色'

  #主頁,這里要填寫可以訪問到的地址,不然驗證不通過
  s.homepage         = 'https://github.com/yanyi0'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  #開源協議
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  #作者
  s.author           = { 'cloud' => '785144130@qq.com' }
  #項目地址,這里不支持ssh的地址,驗證不通過,只支持HTTP和HTTPS,最好使用HTTPS。
  #這里的s.source須指向存放源代碼的鏈接地址,而不是托管spec文件的repo地址
  s.source           = { :git => 'https://github.com/yanyi0/BCAlertView.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  #支持的平臺及版本
  s.ios.deployment_target = '8.0'

  #代碼源文件地址,**/*表示Classes目錄及其子目錄下所有文件,如果有多個目錄下則
  #用逗號分開,如果需要在項目中分組顯示,這里也要做相應的設置

  s.source_files = 'BCAlertView/Classes/**/*'

  #資源文件地址
  # s.resource_bundles = {
  #   'BCAlertView' => ['BCAlertView/Assets/*.png']
  # }
  #公開頭文件地址
  # s.public_header_files = 'Pod/Classes/**/*.h'

  #所需的framework,多個用逗號隔開
    s.frameworks = 'UIKit'
  #依賴關系,該項目所依賴的其他庫,如果有多個需要填寫多個s.dependency
    s.dependency 'Masonry', '~> 1.0.2'
    #s.dependency 'AFNetworking','~> 2.3'
end

打開BCAlertView工程目錄下的BCAlertView.podspec 文件并參考上面的說明配置好相關選項。podspec更多配置請參考:官方文檔

2.編輯完BCAlertView.podspec文件后,需要驗證一下這個BCAlertView.podspec文件是否可用

在Terminal中執行cd進入BCAlertView項目根目錄然后,執行以下命令:

    pod lib lint

此時終端輸出:


WX20180721-193716@2x.png

文件有報錯。修改報錯后,在Example工程目錄下執行 pod update命令安裝依賴(重復第三步)。

重復第四部提交Pod庫到Git倉庫2


WX20180722-005124.png

WX20180722-005333.png

重新編輯BCAlertView.podspec文件

    #
# Be sure to run `pod lib lint BCAlertView.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|  
  #名稱  
  s.name             = 'BCAlertView'  
  #版本號  
  s.version          = '0.0.2'       <font color=red size=18>**第二次修改tag號必須改為>0.01**</font>  
  #簡介  
  s.summary          = 'A short description of BCAlertView.'  

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!
  #描述     
  s.description      = '熱更新彈窗,更新帶進度條漸變色'

  #主頁,這里要填寫可以訪問到的地址,不然驗證不通過  
  s.homepage         = 'https://github.com/yanyi0'  
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'  
  #開源協議  
  s.license          = { :type => 'MIT', :file => 'LICENSE' }  
  #作者  
  s.author           = { 'cloud' => '785144130@qq.com' }  
  #項目地址,這里不支持ssh的地址,驗證不通過,只支持HTTP和HTTPS,最好使用HTTPS。  
  #這里的s.source須指向存放源代碼的鏈接地址,而不是托管spec文件的repo地址  
  s.source           = { :git => 'https://github.com/yanyi0/BCAlertView.git', :tag => s.version.to_s }  
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'  
  
  #支持的平臺及版本  
  s.ios.deployment_target = '8.0'  

  #代碼源文件地址,**/*表示Classes目錄及其子目錄下所有文件,如果有多個目錄下則  
  #用逗號分開,如果需要在項目中分組顯示,這里也要做相應的設置  

  s.source_files = 'BCAlertView/Classes/**/*'  

  #資源文件地址  
  # s.resource_bundles = {  
  #   'BCAlertView' => ['BCAlertView/Assets/*.png']  
  # }  
  #公開頭文件地址  
  # s.public_header_files = 'Pod/Classes/**/*.h'  

  #所需的framework,多個用逗號隔開  
    s.frameworks = 'UIKit'  
  #依賴關系,該項目所依賴的其他庫,如果有多個需要填寫多個s.dependency  
    s.dependency 'Masonry', '~> 1.0.2'  
    #s.dependency 'AFNetworking','~> 2.3'  
end

再次執行:<font size=9>pod lib lint</font>

WX20180722-010820.png

再次執行:<font size=9>pod lib lint --allow-warnings</font>
WX20180722-011634.png

當你看到 Terminal 中輸出:<font size=6>BCAlertView passed validation.</font>
表示這個BCAlertView.podspec 驗證通過,是一個符合CocoaPods規則的配置文件。

3.本地測試BCAlertView.podspec文件

打開Example工程目錄Podfile文件修改下pod 的引用

use_frameworks!
#pod 'BCAlertView', :path => '../' # 指定路徑
target 'BCAlertView_Example' do
  pod 'BCAlertView', :podspec => '../BCAlertView.podspec'

  target 'BCAlertView_Tests' do
    inherit! :search_paths

    pod 'Specta'
    pod 'Expecta'
    pod 'FBSnapshotTestCase'
    pod 'Expecta+Snapshots'
  end
end

然后在Example工程目錄下執行pod update命令安裝依賴,打開項目工程,現在可以看到庫文件都被加載到Pods子項目中了。依賴庫Masonry也導入成功。


WX20180722-013419.png

WX20180722-013759@2x.png

4.向Spec Repo提交podspec

測試庫文件沒有問題我們就把BCAlertView.podspec提交到遠程Spec Repo倉庫中,就是本文開頭說的Git倉庫1
在Terminal中執行 cd進入BCAlertView項目根目錄然后,執行以下命令:

# pod repo push [Repo名] [podspec 文件名字]  
$ pod repo push BlueCloudSpecs BCAlertView.podspec

可能會報錯:


WX20180722-014904.png

此時重新輸入:pod repo push BlueCloudSpecs BCAlertView.podspec --verbose --allow-warnings
如果提交成功,在Terminal會輸出:


WX20180722-015334.png

表示提交成功了!這個組件庫就添加到我們的私有Spec Repo中了,可以進入到~/.cocoapods/repos/BlueCloudSpecs目錄下查看

?  BlueCloudSpecs git:(master) tree
.
├── BCAlertView
│   └── 0.0.2
│       └── BCAlertView.podspec
└── MyLib
    └── 0.1.0
        └── MyLib.podspec

4 directories, 2 files

再去看我們的Spec Repo遠端倉庫 也就是Git倉庫1,也有了一次提交,這個podspec也已經被Push上去了。


WX20180722-015955@2x.png

至此,我們的這個組件庫就已經制作添加完成了,使用pod search命令就可以查到我們自己的庫了.
在Terminal中執行 pod search BCAlerView,此時可能一直報錯。

[!] Unable to find a pod with name, author, summary, or description matching `BCAlertView`
WX20180723-020032.png

解決辦法是:rm ~/Library/Caches/CocoaPods/search_index.json 重新搜索


WX20180723-020401.png
pod search BCAlertView
WX20180723-020614.png

5.常見錯誤

  • 更新本地pod庫失敗
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master`.

解決辦法是:Go to ~/.cocoapods/repos and run git clone https://github.com/CocoaPods/Specs.git master

  • 私有庫pod repo push BlueCloudSpecs DYObject.podspec --verbose --use-libraries --allow-warnings后一直報 is not clean
[!] The repo `BlueCloudSpecs` at `../../.cocoapods/repos/BlueCloudSpecs` is not clean
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/command/repo/push.rb:159:in `check_repo_status'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/command/repo/push.rb:74:in `run'
/Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `<main>'
WX20180727-014937.png

解決辦法是:到本地的私有庫中執行git status,確保nothing to commit, working directory clean,若有未提交的文件,則進行提交。再次執行pod repo push BlueCloudSpecs DYObject.podspec --verbose --use-libraries --allow-warnings能成功。


WX20180727-020047.png

WX20180727-020227.png

四、至此私有庫創建成功,怎么使用自己創建好的私有庫在下一篇文章中給出iOS使用創建的私有庫

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,461評論 6 532
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,538評論 3 417
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,423評論 0 375
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,991評論 1 312
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,761評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,207評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,268評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,419評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,959評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,782評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,983評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,528評論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,222評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,653評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,901評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,678評論 3 392
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,978評論 2 374

推薦閱讀更多精彩內容