在我們做私有庫的時候,發(fā)現(xiàn)默認的情況下,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绒疗、
.podspec
中s.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.
文件夾名字可能寫錯了,改下就好了, 這個有時候輸入快了坟冲,確實容易錯磨镶,還不容易發(fā)現(xiàn)的。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'
這樣就可以規(guī)避了私痹,否則子文件夾不斷引用還是麻煩的脐嫂。