zoukankan      html  css  js  c++  java
  • 第20月第29天 cocoa抽象工厂 cocoapods组件化 cocoapods升级

    1.

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

    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 的意思)

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

    抽象工厂将一系列的产品族统一到一起创建,增加产品族很方便,但增加产品很麻烦,需要改动太多的类的接口。 ####生成器(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 类型的对象。

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

    https://github.com/al1020119/iCocosDesignPattern

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

    https://draveness.me/2017-summary

    2.git pod私有库

     索引库

      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

  • 相关阅读:
    第五周作业
    第四周作业
    第三周作业(两个题)
    第六周作业
    第五周作业
    第四周作业
    第三周作业
    第二周作业
    求最大值及其下标
    查找整数
  • 原文地址:https://www.cnblogs.com/javastart/p/9103291.html
Copyright © 2011-2022 走看看