码迷,mamicode.com
首页 > 其他好文 > 详细

组件化开发-001-本地私有库抽取和远程私有库创建

时间:2018-07-12 10:26:31      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:down   ase   ext   --   depend   全局   should   复制   添加   

1  组件化
组件化最大目的是为了降低功能、项目与项目组件之间很强的依赖,降低耦合度,抽取时优先抽取基础组件,全局属性,封装的AFN等.

2 组件化优缺点:

1.优点:A:降低耦合度

              B:组件单独开发,单独测试

              C:多人协作开发

缺点:版本同步的问题

组件拆分:A:功能拆分(轮播器,网络框架,图片加载,公共基础类,类别,工具类等

                    B:业务拆分(登录,聊天,商城等等

                    C: router (只负责业务之间的业务往来)

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

复制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 youre 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.

本地私有库创建完毕

 第四步:远程私有库创建

 未完,待续~~~~

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

组件化开发-001-本地私有库抽取和远程私有库创建

标签:down   ase   ext   --   depend   全局   should   复制   添加   

原文地址:https://www.cnblogs.com/StevenHuSir/p/ComponentBased.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!