第20月第29天 cocoa抽象工厂 cocoapods组件化 cocoapods升级

1.html

在 Cocoa Touch 框架中,类簇是抽象工厂模式在 iOS 下的一种实现,以 NSArray 举例,将原有的 alloc+init 拆开写:ios

id obj1 = [NSArray alloc]; // __NSPlacehodlerArray *
id obj2 = [NSMutableArray alloc];  // __NSPlacehodlerArray *
id obj3 = [obj1 init];  // __NSArrayI *
id obj4 = [obj2 init];  // __NSArrayM *

发现 + alloc 后并不是生成了咱们指望的类实例,而是一个NSPlacehodlerArray 的中间对象,后面的 – init 或 – initWithXXXXX 消息都是发送给这个中间对象,再由它作工厂,生成真的对象。这里的 NSArrayI 和 __NSArrayM 分别对应 Immutable 和 Mutable(后面的 I 和 M 的意思)git

因而顺着思路猜实现,__NSPlacehodlerArray 一定用某种方式存储了它是由谁 alloc 出来的这个信息,才能在 init 的时候知道要建立的是可变数组仍是不可变数组。github

抽象工厂将一系列的产品族统一到一块儿建立,增长产品族很方便,但增长产品很麻烦,须要改动太多的类的接口。 ####生成器(Builder) 将一个复杂对象的构建与它的表现分离,使得一样的构建过程能够建立不一样的表现。 生成器能够将构建对象的过程分为,客户 – 指导者 – 生成器 的关系,数组

CharacterBuilder *characterBuilder = [[StandarCharacterBuilder alloc] init];
ChasingGame *game = [[ChasingGame alloc] init];

Character *player = [chasingGame createPlayer:characterBuilder];
Character *enemy = [chasingGame createEnemy:characterBuilder];

characterBuilder 就是生成器了,而 game 就是指导者。指导者里声明了建立不一样表现的对象的方法。而方法里由生成器 characterBuilder 来构建不一样的 Character 类型的对象。ruby

  • 生成器模式将复杂的生成对象的过程交给了生成器去完成,做为客户的咱们只须要根据简单的接口去生成不一样表现的对象。如上述代码中的 player 以及 enemy。玩家和敌人具体的属性数值咱们不须要去设置,而是交给生成器去设置。

 

https://github.com/al1020119/iCocosDesignPattern框架

http://ios.jobbole.com/85360/post

https://draveness.me/2017-summaryui

 

2.git pod私有库spa

 索引库

  508  cd ~/.cocoapods/repos/

  509  ls

  510  history

  511  ls

  512  pod repo add MyRepo https://gitee.com/lianhuaren/MyRepo.git

代码库

 

  502  cd Desktop/mycode/

  503  ls

  504  mkdir QinzTool

  505  cd QinzTool/

  506  pod lib create QinzTool

  507  pwd

  508  ls

 

上传模板文件

  509  cd QinzTool/

  510  ls

  511  git remote add origin https://gitee.com/lianhuaren/Tool.git

  512  git push -u origin master

  513  git pull

  514  git push -u origin master

  515  git pull

  516  git branch --set-upstream-to=origin/master master

 

  518  git pull

  519  git pull

 

  521  git pull origin master --allow-unrelated-histories

  522  git push -u origin master

  523  git push -u origin master -f

  524  history

 

将组件的代码上传

  526  git add .

  527  git commit -m "first"

  528  git push -u origin master

 

 

  529  pwd

  530  pod lib lint --private

  531  git tag 0.1.0

  532  git push --tags

  533  pod repo push MyRepo QinzTool.podspec 

 

source 'https://github.com/CocoaPods/Specs.git'
source 'https://gitee.com/lianhuaren/MyRepo'

platform :ios, '8.0'

target 'pods01' do
use_frameworks!

pod 'QinzTool', '~> 0.1.0'
pod 'AFNetworking' #公有库


end

 

 

https://blog.csdn.net/m0_37402140/article/details/72801372

https://blog.csdn.net/shiren1118/article/details/7761203

 

https://www.jianshu.com/p/c1a215b9ddbe

 

 

 

 

more:

 

 1)

没用sourcetree,不会git remote add, 致使失败

也并非在~/.cocoapods/repos/HCocaPodsSpecsManager调用pod lib create HStarTools

 

若是在~/.cocoapods/repos/HCocaPodsSpecsManager调用命令,这样HCocaPodsSpecsManager有.git,HStarTools又有.git

最后致使调用pod repo push HCocaPodsSpecsManager HStarTools.podspec出错。

The repo `HCocaPodsSpecsManager` at `..` is not clean

 

https://www.jianshu.com/p/67a1d8385c80

 

 2)

 若是不用pod lib create QinzTool,开始出现问题。

- ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.

https://www.jianshu.com/p/0c640821b36f

 

 

3) 

下面咱们把 pod push 到远端:

git push --set-upstream origin master

下一步,咱们建立一个私有的 Spec 仓库,这里面存放的是咱们须要的 Pod 的索引,我在 Coding 上建立了一个 MySpec 仓库,咱们先把它加到 CocoaPods 当中:

pod repo add MySpec git@git.coding.net:skyline75489/MySpec.git

这里面如今仍是空的,下面咱们把 XXBaseHeaders push 到仓库中,至关于发布出去:

pod repo push MySpec XXBaseHeaders.podspec --allow-warnings

 

https://skyline75489.github.io/post/2016-3-19_ios_modularization_practice.html

 

 

3.

 

 

sudo gem install cocoapods

 

https://gems.ruby-china.com/

https://blog.csdn.net/potato512/article/details/62235282

相关文章
相关标签/搜索