美文网首页
pod引用本地库

pod引用本地库

作者: IT卡农 | 来源:发表于2019-11-22 16:58 被阅读0次

1.大体描述

项目希望应用App的业务代码分成组件, App内部只保留少量的代码. 所以讲App/目录下: Chat, Common, Information, Mine, Score作为本地库.(也可以在本机的别的目录下,如desktop) (见图1)
其实感觉Common的有些App私有的东西,可以放在App里边,不需要作为库

最后项目的目录结构如下 (见图2)
红框1: 代表app的项目文件, 只有基本的配置文件+AppDelegate
红框2:本地pod库
红框3:远程pod库
注意: 因为导入了本地pod库, 所以自动生成了红框2的"DevelopmentPods"目录

图1.png 图2.png

2.podfile文件

# git库
pod 'AFNetworking', '3.2.1'
pod 'MJRefresh', '3.2.0'
pod 'MJExtension', '3.1.0'
# svn库
pod 'LoginLib', :svn =>'https://xxx/trunk/LoginLib'
pod 'LoginKit', :svn =>'https://xxx/trunk/LoginKit'
# 本地文件
pod 'Common', :path => './xxx/App/Common/'
pod 'Score', :path => './xxx/App/Score/'
pod 'Chat', :path => './xxx/App/Chat/'
pod 'Mine', :path => './xxx/App/Mine/'
pod 'Information', :path => './xxx/App/Information/'

3.podspec文件配置

3.1Chat

  spec.prefix_header_file = 'Chat/Chat.h'
  spec.source_files  = 'Chat', 'Chat/**/*.{h,m}' //代表任何子孙目录的.h.m文件都导入

  spec.resource_bundles = {
    'ChatBundle' => [ 'Chat/Resources/**/*.xcassets',
                      'Chat/Resources/**/*.xib' ]
  }

  spec.frameworks = 'Foundation', 'UIKit', 'CoreLocation', 'CoreGraphics', 'QuartzCore', 'OpenGLES', 'ImageIO', 'SystemConfiguration', 'Security'
  spec.libraries = 'c++', 'z', 'sqlite3', 'icucore'

  spec.dependency 'Common'//Chat依赖Common库
  spec.dependency 'Masonry'

上边podspec的作用, 在项目中的体现(见图3)
注意: 有些文件夹图标左下角没有三角形图标

如图3.png

3.2Common

spec.prefix_header_file = 'Common/Common.h'
  
  spec.source_files  = 'Common/*' //*代表向下一层所有文件, **不但包括子文件也包括孙(孙孙\...)文件
  
  spec.resource_bundles = { 'CommonBundle' => ['Common/Resources/*.xcassets',
                                            'Common/Resources/*.xib',
                                            'Common/Util/UI/KKFont(字体)/src/*.{ttf,OTF}']
  }

  spec.frameworks = 'Foundation', 'UIKit', 'CoreGraphics', 'ImageIO', 'SystemConfiguration', 'Security'
  spec.libraries = 'c++', 'z', 'sqlite3'
 
  spec.dependency 'Bugly'
  spec.dependency 'AMapLocation'
  spec.dependency 'AMapSearch'

####################### subspec ########################
  spec.subspec 'Header' do |header|
    header.source_files = 'Common/Header/**/*.{h,m}'
  end
  
  spec.subspec 'Base' do |base|
    base.source_files = 'Common/Base/**/*.{h,m}'
  end

  spec.subspec 'EventPoint' do |eventPoint |
    eventPoint.source_files = 'Common/EventPoint/**/*.{h,m}'
  end

  spec.subspec 'Util' do |util|
    util.source_files = 'Common/Util/*'
    
    util.subspec 'UI' do |ui|
      ui.source_files = 'Common/Util/UI/**/*.{h,m}'
    end
    
    util.subspec 'Foundation' do |foundation|
      foundation.source_files = 'Common/Util/Foundation/**/*'
      
      foundation.subspec 'NSObjectSafe' do |safe|
        safe.requires_arc = false
        safe.source_files = 'Common/Util/Foundation/NSObjectSafe/**/*.{h,m}'
      end

    end
    
  end
  
  spec.subspec 'Account' do |account|
    account.source_files = 'Common/Account/*.{h,m}'
  end
  
  spec.subspec 'Router' do |router|
    router.source_files = 'Common/Router/*.{h,m}'
  end
  
  spec.subspec 'Configuration' do |configuration|
    configuration.source_files = 'Common/Configuration/*'
    
    configuration.subspec 'Network' do |network|
      network.source_files = 'Common/Configuration/Network/*.{h,m}'
    end
    
    configuration.subspec 'SDK' do |sdk|
      sdk.source_files = 'Common/Configuration/SDK/*.{h,m}'
    end
    
  end

end

podspec中设置了subspec的目录, 都变成了左下角带小三角的样子, 没设置的不带

图4.png

3.3换种方式写Common

 spec.prefix_header_file = 'Common/Common.h'
  
  spec.source_files  = 'Common', 'Common/**/*.{h,m}' //Common下的所有.h.m文件
  
  spec.resource_bundles = { 'CommonBundle' => ['Common/Resources/*.xcassets',
                                            'Common/Resources/*.xib',
                                            'Common/Util/UI/KKFont(字体)/src/*.{ttf,OTF}']
  }

  spec.frameworks = 'Foundation', 'UIKit', 'CoreGraphics', 'ImageIO', 'SystemConfiguration', 'Security'
  spec.libraries = 'c++', 'z', 'sqlite3'
  
  spec.dependency 'Bugly'
  spec.dependency 'AMapLocation'

  ####################### subspec ########################

  spec.subspec 'NSObjectSafe' do |safe|
    safe.requires_arc = false
    safe.source_files = 'Common/**/NSObjectSafe/*.{h,m}'
  end

  ####################### subspec ########################

spec.source_files和subspec还可以这么写
这里的subspec不起子目录作用, 只是指定NSObjectSafe目录下的.h.m文件不要求用ARC

图5.png

3.4总结

1.注意例子中spec.source_files的写法
2.注意subspec的写法, 3.2中在作为远程库时候, 设置了subpec的目录还会以文件夹目录的形式出现(带小三角), 而3.1和3.3的粗暴写法会将主目录(Chat/Common)下的所有.h.m导入进去其中,而没有子目录。
3.requires_arc: 可以对文件作ARC设定

相关文章

  • pod引用本地库

    1.大体描述 项目希望应用App的业务代码分成组件, App内部只保留少量的代码. 所以讲App/目录下: Cha...

  • iOS集成Google 登录

    针对iOS端集成Google登录 1、引用pod库 如安装失败可先更新本地索引 pod repo update国内...

  • 2020-12-07(6)自己_3

    21: pod 本地库 cd 本地项目路径 pod install #如果本地repo库太长时间没更新可以使用下面...

  • 04.Podfile常见使用方法

    1. 常规使用方法 2. 使用本地或者自建的库 3. 如何直接引用本地还未上传至POD库的资源 4. podfil...

  • iOS pod创建本地库

    Xcode pod 本地库 前言 如果没有cocoapods,先安装环境。 创建pod本地库 cd 到项目工程下 ...

  • pod update 与 pod install 的区别

    pod update 更新本地 specs 存储库pod install 根据本地 的 specs po...

  • Cocoapods搜索库出现无法找到解决方案

    更新本地pod库 pod setup 执行搜索,仍然无法搜索继续往下看 删除pod库master文件夹 pod r...

  • 本地私有库与远程私有库

    一、本地私有库: $ pod lib create <库名>:创建本地模版库 通过此命令,我们可以在本地创建模版库...

  • pod本地库

    本地索引库首先拥有一个管理索引库的git地址,在终端执行代码pod repo add IMIPrivateSpec...

  • Cocoapod 常用备记

    指定源 Source 本地引用 基于远程分支引用 基于某一次提交引用 pod 'DLTest', :git => ...

网友评论

      本文标题:pod引用本地库

      本文链接:https://www.haomeiwen.com/subject/xarqwctx.html