iOS组件化

96 阅读2分钟

创建私有库

 首先在Gitee上创建一个YTPrivateBaseKit私有库【注意,除了索引库外,其他组件库不需要添加到repo列表】。然后再使用命令pod lib create [库名]来创建本地项目,例如:



pod lib create YTPrivateBaseKit

#然后回答几个问题

#选择平台
What platform do you want to use?? [ iOS / macOS ]  
> ios

#选择语言
What language do you want to use?? [ Swift / ObjC ]  
> swift

#是否需要Demo
Would you like to include a demo application with your library? [ Yes / No ] 
> yes

#是否使用测试工具
Which testing frameworks will you use? [ Quick / None ]  
> none

#是否进行视图测试
Would you like to do view based testing? [ Yes / No ]  
> no

因为本地 Pod 也会接受主工程的 Git 管理的,所以可以删除 \ECUIKit目录下的 .git ,取消该组件的独立的 Git 管理。需要 删除 .git文件

创建完私有库项目之后,将需要添加的文件放在私有文件中。设置好podspec

#

# Be sure to run `pod lib lint XQBaseModel.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             = 'XQBaseModel'

  s.version          = '0.1.1'

  s.summary          = 'A short description of XQBaseModel.'

  


# 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      = <<-DESC

TODO: Add long description of the pod here.

                       DESC

  


  s.homepage         = 'https://gitee.com/CuanTianHouT/XQBaseModel'

  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'

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

  s.author           = { '151016zkq' => '1510166838@qq.com' }

  s.source           = { :git => 'https://gitee.com/CuanTianHouT/XQBaseModel.git', :tag => s.version.to_s }

  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  


  s.ios.deployment_target = '9.0'

  s.requires_arc         = true

  s.static_framework     = true

  

  s.swift_version = '5.0'

# 创建的类存放的地方

  s.source_files = 'XQBaseModel/Classes/**/*'

  

#  存放资源文件的的地方,必须xib,图片

#  s.resource = ['XQBaseModel/Classes/**/*.png']

  s.xcconfig = {

    'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/Headers/Public"/**'

  }

  s.pod_target_xcconfig  = {

    'ENABLE_BITCODE' => 'NO',

    'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES',

    'GCC_PREPROCESSOR_DEFINITIONS' => 'SD_WEBP=1 MAS_SHORTHAND=1 MAS_SHORTHAND_GLOBALS=1',

    'OTHER_SWIFT_FLAGS' => '$(inherited) -D COCOAPODS -enable-bridging-pch'

  }

  

  

  s.dependency 'MJExtension', '3.4.1'

#  相当于pch文件

#  s.prefix_header_contents = '#import <PLBaseModule/PLBaseModule.h>',

  


  # s.resource_bundles = {

  #   'XQBaseModel' => ['XQBaseModel/Assets/*.png']

  # }

  


#   s.public_header_files = 'Pod/Classes/**/*.h'

  # s.frameworks = 'UIKit', 'MapKit'

  # s.dependency 'AFNetworking', '~> 2.3'

end

将本地代码推送到远程仓库

cd /Users/xxx/Desktop/Modules/XXX
git remote add origin https://gitee.com/xxx/XXX.git
git push -u origin master -f
git add .
git commit -am "提交代码"
git push -u origin master -f
git tag 0.0.1#(注意,这里的tag必须和WJCommon.podspec文件的版本一致)
git push --tags

对本地代码库进行本地验证

$ pod lib lint --allow-warnings # 本地认证

验证通过之后。创建本地spec repo 并上传索引文件到远程仓库

pod repo add XXX https://github.com/willZTK/TestSpecs.git
pod repo push XXX XXX.podspec --allow-warnings

使用

pod 'XXX', :git => "https://gitee.com/XXX/XXX.git", :tag => '1.0.0'