一、創建私有的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 目錄下,大概的文件目錄如下:
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進入要創建項目的目錄然后 執行以下命令:
接著在Terminal控制臺會輸出:
第一個問題是問你選擇iOS還是macOS平臺。此教程選的是iOS。
第二個問題是問你選擇Swift還是Objc構建項目。此教程 選的是ObjC
第三個問題問你是否需要創建一個Demo項目,此教程選的是Yes
第四個問題讓你是否選擇一個測試框架,此教程選 Specta
第五個問題是否基于View測試,選Yes
第六個問題是詢問 類的前綴,設為BC
設置完成后自動打開Xcode并控制臺輸出如下:
成功后會在目錄中創建好一個BCAlertView工程,結構(查看當前目錄結構直接在終端輸入tree,若沒有安裝tree,則輸入brew install tree進行安裝)如下:
├── 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命令安裝依賴
打開項目工程,可以看到庫文件都被加載到Pods子項目中了。
不過它們并沒有在Pods目錄下,而是跟測試項目一樣存在于Development Pods/BCAlertView中,這是因為我們是在本地測試,而沒有把podspec文件添加到Spec Repo中的緣故。測試庫文件沒有問題,接著我們需要執行第4步
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到遠端倉庫
到這里,成功提交到遠程 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
此時終端輸出:
文件有報錯。修改報錯后,在Example工程目錄下執行 pod update命令安裝依賴(重復第三步)。
重復第四部提交Pod庫到Git倉庫2
重新編輯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>
再次執行:<font size=9>pod lib lint --allow-warnings</font>
當你看到 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也導入成功。
4.向Spec Repo提交podspec
測試庫文件沒有問題我們就把BCAlertView.podspec提交到遠程Spec Repo倉庫中,就是本文開頭說的Git倉庫1
在Terminal中執行 cd進入BCAlertView項目根目錄然后,執行以下命令:
# pod repo push [Repo名] [podspec 文件名字]
$ pod repo push BlueCloudSpecs BCAlertView.podspec
可能會報錯:
此時重新輸入:pod repo push BlueCloudSpecs BCAlertView.podspec --verbose --allow-warnings
如果提交成功,在Terminal會輸出:
表示提交成功了!這個組件庫就添加到我們的私有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上去了。
至此,我們的這個組件庫就已經制作添加完成了,使用pod search命令就可以查到我們自己的庫了.
在Terminal中執行 pod search BCAlerView,此時可能一直報錯。
[!] Unable to find a pod with name, author, summary, or description matching `BCAlertView`
解決辦法是:rm ~/Library/Caches/CocoaPods/search_index.json 重新搜索
pod search BCAlertView
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>'
解決辦法是:到本地的私有庫中執行git status,確保nothing to commit, working directory clean,若有未提交的文件,則進行提交。再次執行pod repo push BlueCloudSpecs DYObject.podspec --verbose --use-libraries --allow-warnings能成功。