iOS 组件库(私有库)文件层分层

在我们做私有库的时候,发现默认的情况下,Pod 出来的文件是木有子文件夹分层的

Masonry 木有分层

而从维护和好看的角度都是想看到分层的,例如 AFNetworking

AFNetworking

通过观察 .podspec 可以看到:

 s.source_files = 'Masonry/*.{h,m}'
  s.source_files = 'AFNetworking/AFNetworking.h'

  s.subspec 'Serialization' do |ss|
    ss.source_files = 'AFNetworking/AFURL{Request,Response}Serialization.{h,m}'
  end

  s.subspec 'Security' do |ss|
    ss.source_files = 'AFNetworking/AFSecurityPolicy.{h,m}'
  end

  s.subspec 'Reachability' do |ss|
    ss.ios.deployment_target = '9.0'
    ss.osx.deployment_target = '10.10'
    ss.tvos.deployment_target = '9.0'

    ss.source_files = 'AFNetworking/AFNetworkReachabilityManager.{h,m}'
  end

  s.subspec 'NSURLSession' do |ss|
    ss.dependency 'AFNetworking/Serialization'
    ss.ios.dependency 'AFNetworking/Reachability'
    ss.osx.dependency 'AFNetworking/Reachability'
    ss.tvos.dependency 'AFNetworking/Reachability'
    ss.dependency 'AFNetworking/Security'

    ss.source_files = 'AFNetworking/AF{URL,HTTP}SessionManager.{h,m}', 'AFNetworking/AFCompatibilityMacros.h'
  end

基本可以得出,默认的情况下,我们是这样的:

 s.source_files = 'XXPod/Classes/**/*'

一、分层

# 第二层文件夹名称 Extensions
  s.subspec 'XXX' do |ss|
      # 下所有的.h和.m文件
      ss.source_files = 'XXPod/Classes/XXX/*.{h,m}'
  end

Example:

  • 1-1、文件夹


    文件夹显示
  • 1-2、.podspecs.source_files

  s.source_files = 'XMPageScrollView/Classes/XMPageScrollView.{h,m}','XMPageScrollView/Classes/XMPageScrollViewProtocol.h'

  s.subspec 'XMTableView' do |ss|
    ss.source_files = 'XMPageScrollView/Classes/XMTableView/*.{h,m}'
  end

  s.subspec 'XMSegmentView' do |ss|
    ss.source_files = 'XMPageScrollView/Classes/XMSegmentView/*.{h,m}'
  end

  s.subspec 'XMCollectionView' do |ss|
    ss.source_files = 'XMPageScrollView/Classes/XMCollectionView/*.{h,m}'
  end
  • 1-3、效果显示:


    Example 效果

二、分层遇到的问题

pod lib lint 遇到的问题:

  • 2-1、file patterns: The 'source_files' pattern did not match any file.
    文件夹名字可能写错了,改下就好了, 这个有时候输入快了,确实容易错,还不容易发现的。

  • 2-2、 fatal error: 'xxx.h' file not found
    这个通常是依赖关系没有处理好的,找到xxx.h 引用他就好了

s.subspec 'Test' do |ss|
      # 下载Test下所有的.h和.m文件
      ss3.source_files = 'XXPod/Classes/Test/**/*'
      ss3.dependency  'XXPod/Classes/xxx'
end

注意此处里面是各个文件夹的依赖,通常这种其实可以用一个公共的头文件

s.souce_files = 'XXPod/Classes/xxx.h'

这样就可以规避了,否则子文件夹不断引用还是麻烦的。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容