1.大體描述
項(xiàng)目希望應(yīng)用App的業(yè)務(wù)代碼分成組件, App內(nèi)部只保留少量的代碼. 所以講App/目錄下: Chat, Common, Information, Mine, Score作為本地庫.(也可以在本機(jī)的別的目錄下,如desktop) (見圖1)
其實(shí)感覺Common的有些App私有的東西,可以放在App里邊,不需要作為庫
最后項(xiàng)目的目錄結(jié)構(gòu)如下 (見圖2)
紅框1: 代表app的項(xiàng)目文件, 只有基本的配置文件+AppDelegate
紅框2:本地pod庫
紅框3:遠(yuǎn)程pod庫
注意: 因?yàn)閷?dǎo)入了本地pod庫, 所以自動(dòng)生成了紅框2的"DevelopmentPods"目錄
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文件都導(dǎo)入
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的作用, 在項(xiàng)目中的體現(xiàn)(見圖3)
注意: 有些文件夾圖標(biāo)左下角沒有三角形圖標(biāo)
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中設(shè)置了subspec的目錄, 都變成了左下角帶小三角的樣子, 沒設(shè)置的不帶
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
3.4總結(jié)
1.注意例子中spec.source_files的寫法
2.注意subspec的寫法, 3.2中在作為遠(yuǎn)程庫時(shí)候, 設(shè)置了subpec的目錄還會(huì)以文件夾目錄的形式出現(xiàn)(帶小三角), 而3.1和3.3的粗暴寫法會(huì)將主目錄(Chat/Common)下的所有.h.m導(dǎo)入進(jìn)去其中,而沒有子目錄。
3.requires_arc: 可以對(duì)文件作ARC設(shè)定