p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
1 组件化:
组件化最大目的是为了降低功能、项目与项目组件之间很强的依赖,降低耦合度,抽取时优先抽取基础组件,全局属性,封装的AFN等.
2 组件化优缺点:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #aa7942 }
span.s1 { color: #0433ff }
span.s2 { color: #000000 }
span.s3 { color: #ff2600 }
span.s4 { color: #ff40ff }
1.优点:A:降低耦合度
B:组件单独开发,单独测试
C:多人协作开发
缺点:版本同步的问题:
组件拆分:A:功能拆分(轮播器,网络框架,图片加载,公共基础类,类别,工具类等)
B:业务拆分(登录,聊天,商城等等)
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
C: router (只负责业务之间的业务往来)
3 组件化步骤:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
span.s1 { color: #000000 }
第一步:新建一个名为HKTools的工程,在工程目录下创建一个名为Lib的文件夹
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
1>创建 Podfile 文件
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
cd /Users/MengYu/Desktop/HKTools
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
span.Apple-tab-span { white-space: pre }
pod init
ls 查看所有文件 HKTools HKTools.xcodeproj Podfile
2>创建模板:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
span.s2 { color: #ff2600 }
cd /Users/MengYu/Desktop/HKTools/Lib/
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
pod lib create HKTools
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff; min-height: 25.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #aa7942; background-color: #ffffff }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #d53bd3; background-color: #ffffff }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #5230e1; background-color: #ffffff }
p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #34bc26; background-color: #ffffff }
p.p7 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #afad24; background-color: #ffffff }
span.s1 { }
span.s2 { color: #afad24 }
span.s3 { color: #000000 }
span.s4 { color: #34bc26 }
span.s5 { text-decoration: underline }
span.s6 { text-decoration: underline; color: #000000 }
span.s7 { color: #d53bd3 }
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?
> [email protected]
! Setting your email in git to [email protected]
git config user.email "91610[email protected]"
------------------------------
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的工程
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
第二步:抽取本地私有库
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
选取本地基础组件库Common文件夹到HKTools下的ReplaceMe.m中,替换 ReplaceMe.m
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
把Replace 删掉 替换成Common文件夹
第三步:重新install,另外新起一个终端 cd 到HKTools工程下的Podfile路径
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
cd /Users/MengYu/Desktop/HKTools/Lib/HKTools/Example/Podfile
pod install 进行安装
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
添加其他依赖:source 远程私有库
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #272ad8; background-color: #ffffff }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; background-color: #ffffff; min-height: 25.0px }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #ba2da2; background-color: #ffffff }
span.s1 { color: #000000 }
span.s2 { color: #272ad8 }
span.s3 { color: #ba2da2 }
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
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #272ad8 }
span.s1 { color: #000000 }
span.s2 { color: #000000; background-color: #ffffff }
span.s3 { background-color: #ffffff }
复制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
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
在本工程Podfile路径下,使用pod install 安装依赖
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #34bc26; background-color: #ffffff }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #000000; background-color: #ffffff; min-height: 25.0px }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #ff2600 }
span.s1 { }
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.
本地私有库创建完毕
第四步:远程私有库创建
未完,待续~~~~
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #0433ff }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC" }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "Yuanti SC"; color: #0433ff }
原文地址:https://www.cnblogs.com/StevenHuSir/p/ComponentBased.html