1 组件化:将一个工程分解为各个组件,然后按照某种方式任意组织成为一个拥有完整逻辑的工程
组件化最大目的是为了降低功能、项目与项目组件之间很强的依赖,降低耦合度,抽取时优先抽取基础组件,全局属性,封装的AFN等.
2 组件化优缺点:
1.优点:A:组件的独立性,降低耦合度
B: 资源重用
C:高效独立(组件单独开发,单独测试)
D:多人协作开发
E : 加快项目的编译速度
缺点:版本同步的问题:
组件拆分:A:功能拆分(轮播器,网络框架,图片加载,公共基础类,类别,工具类等)
B:业务拆分(登录,聊天,商城等等)
C: router (只负责业务之间的业务往来)
①基础组件
基础配置(宏,常量),分类,网络(AFN,SDW二次封装)、工具类(日期时间的处理,文件处理,设备处理)
②功能组件
控件(弹幕,轮播器,选项卡);功能(断点续传,音频处理)
③业务组件
业务线一,业务线二。
spec文件,描述框架信息
3 组件化步骤:
第一步:新建一个名为HKTools的工程,在工程目录下创建一个名为Lib的文件夹
1>创建 Podfile 文件
cd /Users/MengYu/Desktop/HKTools
pod init
ls 查看所有文件 HKTools HKTools.xcodeproj Podfile
2>创建模板:
cd /Users/MengYu/Desktop/HKTools/Lib/
pod lib create HKTools
Cloning `https://github.com/CocoaPods/pod-template.git` into `HKTools`.
Configuring HKTools template.
! Before you can create a new library we need to setup your git credentials.
//填写基本信息
What is your email?
> 916109796@qq.com
! Setting your email in git to 916109796@qq.com
git config user.email "916109796@qq.com"
------------------------------
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide:
- https://guides.cocoapods.org/making/using-pod-lib-create.html
( hold cmd and double click links to open in a browser. )
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> ObjC
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> No
What is your class prefix?
> HK
Running pod install on your new library.
Analyzing dependencies
Fetching podspec for `HKTools` from `../`
Downloading dependencies
Installing HKTools (0.1.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `HKTools.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
[!] Automatically assigning platform `ios` with version `9.3` on target `HKTools_Example` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
Ace! you're ready to go!
We will start you off by opening your project in Xcode
open 'HKTools/Example/HKTools.xcworkspace'
To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
To learn more about creating a new pod, see `http://guides.cocoapods.org/making/making-a-cocoapod`.
此时会自动打开一个名为HKTools的工程
第二步:抽取本地私有库
选取本地基础组件库Common文件夹到HKTools下的ReplaceMe.m中,替换 ReplaceMe.m
把Replace 删掉 替换成Common文件夹
第三步:重新install,另外新起一个终端 cd 到HKTools工程下的Podfile路径
cd /Users/MengYu/Desktop/HKTools/Lib/HKTools/Example/Podfile
pod install 进行安装
添加其他依赖:source 远程私有库
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0' use_frameworks! target 'HKTools_Example' do pod 'HKTools', :path => '../' target 'HKTools_Tests' do inherit! :search_paths pod 'AFNetworking', '~> 3.1.0' end end
添加其他依赖:报错
//Lexical or Preprocessor Issue ‘*.h’ file not found
原因分析:pod 依赖位置添加错误
错误❌未注释use_frameworks!
正确✅注释use_frameworks!
复制pod 'HKTools', :path => './Lib/HKTools' 到本工程下的Podfile文件中
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0' use_frameworks! target 'HKTools' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks # use_frameworks! # Pods for HKTools pod 'HKTools', :path => './Lib/HKTools' end
在本工程Podfile路径下,使用pod install 安装依赖
Installing HKTools (0.1.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `HKTools.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
本地私有库创建完毕
第四步:远程私有库创建
在码云上新建一个项目:
接下来:复制此路径
https://gitee.com/Steven_Hu/HKTools.git
找到本工程下的HKTools路径 ,上传本地版本
cd /Users/MengYu/Desktop/HKTools/Lib/HKTools/
git remote add origin https://gitee.com/Steven_Hu/HKTools.git
git push origin master -f 全局提交
但目前是没有东西的
cd /Users/MengYu/Desktop/HKTools/Lib/HKTools/
git add .
git commit -m 'HKTools初始化'
git push origin master
Writing objects: 100% (95/95), 121.57 KiB | 4.50 MiB/s, done.
Total 95 (delta 32), reused 0 (delta 0)
remote: Powered by Gitee.com
To https://gitee.com/Steven_Hu/HKTools.git
6c57575..8c3fe8a master -> master
上传成功~
如何删除项目:
第五步:.podspec文件详解(修改)
Pod::Spec.new do |s| s.name = 'HKTools' s.version = '0.1.0' s.summary = 'HKTools工具类.' # 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 = 'HKTools工具类.' s.homepage = 'https://gitee.com/Steven_Hu' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'HJT916109796' => '916109796@qq.com' } s.source = { :git => 'https://gitee.com/Steven_Hu/HKTools.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>' s.ios.deployment_target = '8.0' s.source_files = 'HKTools/Classes/**/*' # s.resource_bundles = { # 'HKTools' => ['HKTools/Assets/*.png'] # } # s.public_header_files = 'Pod/Classes/**/*.h' # s.frameworks = 'UIKit', 'MapKit' # s.dependency 'AFNetworking', '~> 2.3' end
git add .
git commit -m '修改.podsepc 文件'
git push origin master
设置Tag
git tag
git tag '0.1.0'
git tag 查看
0.1.0
git push --tags //提交
查看本地索引库:
pod repo
master
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/MengYu/.cocoapods/repos/master
命令校对文件是否可用
验证本地:
pod lib lint
-> HKTools
验证远程:
pod spec lint
-> HKTools (0.1.0)
- WARN | description: The description is equal to the summary.
修改已知报错信息后,pod repo push master HKTools 无法提交
进入本地索引库:
Pod search HKTools
抽取成功~