美文网首页
使用Cocoapods管理自己github上的项目,并让其支持p

使用Cocoapods管理自己github上的项目,并让其支持p

作者: yuandiLiao | 来源:发表于2017-08-28 18:06 被阅读0次

如何在GitHub上面创建项目就不写了,这里记录一下用Cocoapods管理。

1.创建 .podspec 文件进行配置

  • 打开终端
  • cd到该项目的本地目录
  • 执行 pod spec create + 前缀名称(例:xxx.podpec , 该xxx就是前缀名称,建议使用你的库名称) 创建 .podspec 文件
  • 用XCode打开创建好的xxx.podpec文件,把里面的东西全部删除重新编辑如下,对应得替换成你工程的。
 Pod::Spec.new do |s|

    s.name         = 'YDModel'
    s.version      = '1.1'
    s.summary      = 'swift模型解析'
    s.homepage     = 'https://github.com/yuandiLiao/YDModel'
    s.license      = 'MIT'
    s.authors      = { "yuandiLiao" => "15019483722" }
    s.platform     = :ios, '8.0'
    s.source       = {:git => 'https://github.com/yuandiLiao/YDModel.git', :tag => s.version}
    s.source_files = 'YDModel/**/*'
    s.requires_arc = true
    s.description  = <<-DESC

    YDModel is for easier to use
    DESC
    end

  • 然后可以commit到GitHub上面了。

2.配置GitHub上面的tag(其实就是版本)

在终端该项目工作目录下执行

git tag '1.0'  (xxx必须是你在 .podspec 文件中的 version(版本号))
git push --tags
git push origin master

执行完该操作后执行pod lib lint,查看你的.podspec文件是否配置成功。

pod lib lint

成功如下


WechatIMG3.jpeg

我管理的swift库,有可能会报swift版本的问题。如下

  - WARN  | [iOS] swift_version: 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`

[!] YDModel did not pass validation, due to 1 warning (but you can
use `--allow-warnings` to ignore it).
You can use the `--no-clean` option to inspect any issue.

解决方法, 在终端执行,把swift环境改到3.0就行了,这里看你的swift版本需求来改

    `echo "3.0" > .swift-version`

3.发布到 Cocoapods 进行管理

在终端该项目目录下执行

 pod trunk push 

发布成功


WechatIMG4.jpeg

这时候直接去执行 pod search 的时候你会发现搜索不到,因为需要更新一下cocoapods的缓存
前往

~/Library/Caches/CocoaPods

把search_index.json 删除
然后执行

pod repo update 

这次去pod search 应该就能搜索到刚刚发布成功的库了

相关文章

网友评论

      本文标题:使用Cocoapods管理自己github上的项目,并让其支持p

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