CocoaPod集成自己的管理库

组件化之-CocoaPods管理自己的公有库

什么是Cocoapods?

来自官网的解释
CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 46 thousand libraries and is used in over 3 million apps. CocoaPods can help you scale your projects elegantly.

管理的优点

1.分工明确,提示开发效率

2.降低耦合度,更加灵活

3.提高代码质量,方便单元测试

4.回滚代码更方便,更容易上手

首先说下大致流程

  • github上创建自己的项目
  • cd到本地添加自己的工程代码,并上传git 打tag
  • 创建pod对应的文件(podspec)包含此公开库的基本信息
  • Cocoapods上注册并Trunk (会有邮件验证)
  • 手动检测.podspec文件是否正确 (pod spec lint)
  • 检测成功提交自己的.podspec公有库

具体流程如下
[图片上传失败...(image-dd6d39-1526278119908)]
创建自己的工程此处略过
cd 到自己的工程路径后创建.podspec文件

"your project name" 是podspec的名称,一般与github上创建的项目名称一样
pod spec create "your project name"

接着将你自己的开源库代码发布到github上

此处注意一定要加V
 git tag "v1.0.0"
注意tag值前的v
5.将tag添加远程仓库
$ git push --tag
$ git push origin master

主要讲下遇到的问题.podspec文件的设置问题

  • iOS系统的设置不能忽略
    如下:
这个几项默认是被注释的 你需要标明平台类型不然会包找不到“UIKIt.h”文件等一系列错误
 s.platform     = :ios
  # s.platform     = :ios, "5.0"

  #  When using multiple platforms
  s.ios.deployment_target = "5.0"
  • 识别路径要设置正确
    s.source_files  = "**/*.{h,m}"
    位于哪个文件夹 ** 文件夹通配符 默认标明的是.podspec的同级别路径
#
#  Be sure to run `pod spec lint ADCCocoaPods.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  These will help people to find your library, and whilst it
  #  can feel like a chore to fill in it's definitely to your advantage. The
  #  summary should be tweet-length, and the description more in depth.
  #

  s.name         = "ADCCocoaPods"
  s.version      = "1.0.3"
  s.summary      = "Delightful, simple library for aspect oriented programming.."

  # 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.homepage     = "https://github.com/Z-Kevin/ADCCocoaPods"
  # s.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


  # ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Licensing your code is important. See http://choosealicense.com for more info.
  #  CocoaPods will detect a license file if there is a named LICENSE*
  #  Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
  #

  s.license      = { :type => 'MIT', :file => 'LICENSE' }
  # s.license      = { :type => "MIT", :file => "FILE_LICENSE" }


  # ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the authors of the library, with email addresses. Email addresses
  #  of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
  #  accepts just a name if you'd rather not provide an email address.
  #
  #  Specify a social_media_url where others can refer to, for example a twitter
  #  profile URL.
  #

  s.author             = { "张晓宇" => "[email protected]" }
  # Or just: s.author    = "张晓宇"
  # s.authors            = { "张晓宇" => "[email protected]" }
  # s.social_media_url   = "http://twitter.com/张晓宇"

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If this Pod runs only on iOS or OS X, then specify the platform and
  #  the deployment target. You can optionally include the target after the platform.
  #

  s.platform     = :ios
  # s.platform     = :ios, "5.0"

  #  When using multiple platforms
  s.ios.deployment_target = "5.0"
  # s.osx.deployment_target = "10.7"
  # s.watchos.deployment_target = "2.0"
  # s.tvos.deployment_target = "9.0"


  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the location from where the source should be retrieved.
  #  Supports git, hg, bzr, svn and HTTP.
  #

  s.source       = { :git => "https://github.com/Z-Kevin/ADCCocoaPods.git", :tag => "v#{s.version}" }


  # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  CocoaPods is smart about how it includes source code. For source files
  #  giving a folder will include any swift, h, m, mm, c & cpp files.
  #  For header files it will include any header in the folder.
  #  Not including the public_header_files will make all headers public.
  #
  s.source_files  = "**/*.{h,m}"
  # s.exclude_files = "Classes/Exclude"

  # s.public_header_files = "Classes/**/*.h"


  # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  A list of resources included with the Pod. These are copied into the
  #  target bundle with a build phase script. Anything else will be cleaned.
  #  You can preserve files from being cleaned, please don't preserve
  #  non-essential files like tests, examples and documentation.
  #

  # s.resource  = "icon.png"
  # s.resources = "Resources/*.png"

  # s.preserve_paths = "FilesToSave", "MoreFilesToSave"


  # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Link your library with frameworks, or libraries. Libraries do not include
  #  the lib prefix of their name.
  #

  # s.framework  = "SomeFramework"
  # s.frameworks = "SomeFramework", "AnotherFramework"

  # s.library   = "iconv"
  # s.libraries = "iconv", "xml2"


  # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If your library depends on compiler flags you can set them in the xcconfig hash
  #  where they will only apply to your library. If you depend on other Podspecs
  #  you can include multiple dependencies to ensure it works.

  s.requires_arc = true

  # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
  # s.dependency "JSONKit", "~> 1.4"

end

正确的提示如下:


CocoaPod集成自己的管理库_第1张图片
478804fa-1cf1-4f04-9d40-f2d2c51215f8.png

成功发布如下


CocoaPod集成自己的管理库_第2张图片
071ed1a3-c999-4e45-a7cf-767b7a7cf910.png

https://www.cnblogs.com/anywherego/p/11149609.html

目前iOS组件化常用的解决方案是Pod+路由+持续集成,通常架构设计完成后第一步就是将原来工程里的模块按照架构图分解为一个个独立的pod工程(组件),今天我们就来看看如何创建一个Pod私有库。

pod lib create

假设我们需要创建的库名为TestLib,下面我们使用Pod官方提供的创建模板:
配置好以后我们需要做一次验证,在工程目录下使用命令

pod lib lint

https://www.cnblogs.com/anywherego/p/11149609.html

你可能感兴趣的:(CocoaPod集成自己的管理库)