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阅读 216,402评论 6 499
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,377评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,483评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,165评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,176评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,146评论 1 297
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,032评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,896评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,311评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,536评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,696评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,413评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,008评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,659评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,815评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,698评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,592评论 2 353

推荐阅读更多精彩内容