一、创建私有的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上面创建。
*在终端执行以下命令。
注意:这个Git 仓库地址要换成你自己的创建的 Specs git 地址!!!
成功后会在~/.cocoapods/repos目录下就能看到MySpecs了,至此,第一步创建私有
Spec Repo就完成了。
二、创建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能成功。