如何制作自己的Pod库

作者: jacinzhang | 来源:发表于2016-03-05 04:02 被阅读1691次
  • GitHub新建自己的git repository


    NewRepositoryNewRepository
  • 将项目clone到本地
    git clone git@github.com:ZHANGMRXIN/ZXCategory.git

    CloneReposiortyCloneReposiorty
  • 初始化好项目,将Pod库文件建立好目录


    PodFileDirectoryPodFileDirectory
  • 给仓库创建个podspec文件
    pod spec create ZXCategory git@github.com:ZHANGMRXIN/ZXCategory.git

    CreatePodSpecCreatePodSpec
  • 编写ZXCategory.podspec文件

项目中不做子目录分层显示

Pod::Spec.new do |s|
  s.name             = "ZXCategory"
  s.version          = "0.0.6"
  s.summary          = "Custom Category used on iOS."
  s.description      = <<-DESC
                       Custom Category used on iOS, which implement by Objective-C.
                       DESC
  s.homepage         = "https://github.com/ZHANGMRXIN/ZXCategory"
  s.license          = 'MIT'
  s.author           = { "xinzhang" => "zx270611346@gmail.com" }
  s.platform         = :ios, '7.0'
  s.source           = { :git => "https://github.com/ZHANGMRXIN/ZXCategory.git", :tag => s.version }
  s.source_files     = 'ZXCategory/**/*'
  s.requires_arc     = true
end

项目中做子目录分层显示

Pod::Spec.new do |s|
  s.name             = "ZXCategory"
  s.version          = "0.0.6"
  s.summary          = "Custom Category used on iOS."
  s.description      = <<-DESC
                       Custom Category used on iOS, which implement by Objective-C.
                       DESC
  s.homepage         = "https://github.com/ZHANGMRXIN/ZXCategory"
  s.license          = 'MIT'
  s.author           = { "xinzhang" => "zx270611346@gmail.com" }
  s.platform         = :ios, '7.0'
  s.source           = { :git => "https://github.com/ZHANGMRXIN/ZXCategory.git", :tag => s.version }
  s.requires_arc     = true

# UIView 和 EasyLog 在工程中以子目录显示
  s.subspec 'UIView' do |ss|
    ss.source_files = 'ZXCategory/UIView/*.{h,m}'
  end

  s.subspec 'EasyLog' do |ss|
    ss.source_files = 'ZXCategory/EasyLog/*.{h,m}'
  end

end

*** s.source_files = ' '*** 的多种写法

ss.source_files = 'ZXCategory/UIView/*.{h,m}'

表示ZXCategory/UIView/目录下的所有 .h.m 文件

s.source_files = 'ZXCategory/**/ .'
/后面的 . 应是 星号,MarkDowm语法冲突在此不能正常显示

表示ZXCategory/ 目录下所有文件,包括子目录下所有文件。 **/.表示递归

当有多个文件时,应用,隔开

 s.source_files = 'MMDrawerController/MMDrawerController.{h,m}', 'MMDrawerController/UIViewController+MMDrawerController*'

  • 把当前版本上传到GitHub,并打上tag(版本号) 即tag => s.version 并确保tag push到GitHub
    git push origin --tags

    PushTagsPushTags
  • 检查ZXCategory.podspec文件是否编写争取
    pod lib lint

    CheckPodSpecCheckPodSpec
  • 将ZXCategory.podspec文件上传给CocoaPods
    pod Trunk 注册
    pod trunk register zx270611346@gmail.com 'ZXCategory'

    检查成功与否
    登录邮箱,点击确认
    终端输入 pod trunk me

    PodTrunkPodTrunk
  • 上传ZXCategory.podspec 到 CocoaPods/repo
    pod trunk push ZXCategory.podspec

    PodspecPushSuccessPodspecPushSuccess

shit! 报错,貌似上传的版本不能小于之前的版本,CocoaPods 为了使用的人着想,要求向下作兼容。

DuplicateErrorDuplicateError
  • 检测是否上传成功
    pod search ZXCategory

    PushSearchCheckPushSearchCheck
  • Done
    执行 pod install or pod install --no-repo-update命令

    UsePodUsePod
  • 另附获取提交到GitHub上的图片资源的两种链接

https://raw.githubusercontent.com/ZHANGMRXIN/ZXCategory/master/Resources/NewProject.png
https://github.com/ZHANGMRXIN/ZXCategory/raw/master/Resources/NewProject.png

参考:
CocoaPods
DWCategory
MMDrawerController

相关文章

  • 制作Pod库

    目录 一、公有Pod库制作 二、私有Pod库制作 三、subspec子库的制作 四、遇到的坑 一、公有Pod库制作...

  • 创建自己的pod库并上传

    参考:如何制作自己的Pod库 - 简书 报错 ··· error: include of non-modular ...

  • 如何制作自己的Pod库

    1、创建仓库: 2、将仓库克隆本地: git clone https://github.com/236021963...

  • 如何制作自己的Pod库

    GitHub新建自己的git repositoryNewRepository 将项目clone到本地git clo...

  • 制作自己的Cocoapods

    制作自己的Cocoapods 创建自己私有pod库,官方推荐使用 pod lib create [pod name...

  • Cocopods 提示target has transitive

    制作自己的pod库时,依赖其他第三方库,在pod install时提示: 解决方案:在自己的pod库.podspe...

  • 如何制作Pod库

    需求: 管理一些常用的类或者第三方的SDK; 组件化开发; 具体步骤: 1. 打开终端,进入要建立私有库项目工程的...

  • iOS:CocoaPods制作私有库

    本章制作私有库方法省去了繁琐的Pod校验,快速简单制作私有库。 创建索引库 我使用的是GitHub 制作Pod 再...

  • 制作自己的Pod库

    首先在github新建repogithub.png clone仓库至本地clone.png 初始化项目initia...

  • 制作自己的pod库

    开发中,如果有比较成熟的组件或代码库想要开放给别人使用,制作成pod库是很好的选择:一方面便于用户使用,另一方面版...

网友评论

  • 骨古:谢谢楼主 有一个问题 组件里怎么显示多级文件夹(大于两级的)目前是定义了几个subspec 和source_files 但是只能显示两级 请问第三级怎么显示 比如(TestKit>>category>>nsstring)
  • a125b5f21024:感谢楼主,非常有用
    不过我在使用的时候还是遇到几个问题
    1.我的pod版本比较老1.0.1,要更新下才能使用,否则一直提示abort 6
    2.我上传的是OC库,上传的时候提示如下错误
    [!] The spec did not pass validation, due to 4 warnings (but you can use `--allow-warnings` to ignore them).
    [!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
    `echo "2.3" > .swift-version`.
    所以需要运行echo "2.3" > .swift-version
    然后忽略警告pod trunk push 库名.podspec --allow-warnings

本文标题:如何制作自己的Pod库

本文链接:https://www.haomeiwen.com/subject/brgokttx.html