建立組件工程
建立主workspace工程與組件的pod工程如(podLibTest)
多個模式共存
源碼模式的podspec
arc與non arc共存問題
在組件工程比較好解決這個問題,當時對于podsepc文件,可以在podspec文件里面建立兩個subspec,一個存放arc的源碼,一個存放non arc的源碼,參考文章最后的示例。引用主工程
如果組件源碼需要引入主工程的文件,而這個文件又不能遷移至組件工程里面,運行組件工程時,可以添加這些源碼文件的搜索路徑,然后拖拽到工程便可(不用copy),對于podspec文件,同時需要添加組件工程的頭文件搜索路徑
s.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '$(PROJECT_DIR)/../Logger/** $(PROJECT_DIR)/../config/** $(PROJECT_DIR)/../Debug/Header' }
- 組件pch文件修改
對于組件工程,有時候為了方便,會開啟pch文件的支持,而通過pod導入的組件,如果需要pod組件同時也支持pch中文件,添加頭文件,可以在podspec中加入
s.prefix_header_contents = '#import <UIKit/UIKit.h>'
源碼、debug、release模式切換
組件的默認模式為release模式,開發者在主工程的時候可以通過不同方式的pod install
來切換不同模式
SOURCE=1 pod install --no-repo-update
//源碼模式
上述指令把組件源碼直接clone到主工程中調試,如果需要制定本地組件倉庫的話,可以修改podfile文件
如
pod 'podLibTest', :path =>'~/workspace/MyComponent/podLibTest/'
DEBUG=1 pod install --no-repo-update
//debug模式
RELEASE=1 pod install --no-repo-update
//release模式
注意:每次push到主工程中的commit,一定要確保組件模式為默認(release模式)
源碼模式的spec可以參考以下
Pod::Spec.new do |s|
s.name = 'podLibTest'
s.version = '1.0.20'
s.summary = 'podLibTest'
s.description = 'podLibTest組件源碼+二進制庫'
s.homepage = 'http://git.test.com/MyComponent/podLibTest'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'dzz' => 'test@google.com.cn' }
s.source = { :git => 'ssh://git@git.test.com:8018/MyComponent/podLibTest.git', :tag => s.version.to_s }
# s.requires_arc = true
s.platform = :ios
s.ios.deployment_target = '8.0'
if ENV['SOURCE']
puts '----- SOURCE MODE -----'
s.default_subspec = 'All'
s.subspec 'All' do |s|
s.ios.dependency 'podLibTest/core'
s.ios.dependency 'podLibTest/non_arc'
s.prefix_header_contents = '#import <UIKit/UIKit.h>','#import <Foundation/Foundation.h>','#import <CocoaLumberjack/CocoaLumberjack.h>','#import "MyLogDefines.h"','#import "MyResult.h"','#import "MyConstants.h"','#import "MyLogMacro.h"'
s.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '$(PROJECT_DIR)/../Logger/** $(PROJECT_DIR)/../config/** $(PROJECT_DIR)/../Debug/Header' }
end
s.subspec 'core' do |s|
non_arc_files = 'podLibTest/Array/Foundation+Security.m','podLibTest/Regex/Regex.m'
s.exclude_files = non_arc_files
s.requires_arc = true
s.source_files = 'podLibTest/**/*.{h,m,mm}'
end
s.subspec 'non_arc' do |s|
non_arc_files = 'podLibTest/Array/Foundation+Security.m','podLibTest/Regex/Regex.m'
s.requires_arc = false
s.source_files = non_arc_files
end
elsif ENV['DEBUG']
puts '----- DEBUG MODE -----'
s.vendored_frameworks = 'Products/debug/universal/podLibTest.framework'
elsif ENV['RELEASE']
puts '----- RELEASE MODE -----'
s.vendored_frameworks = 'Products/release/iphoneos/podLibTest.framework'
else
puts '----- DEFAULT RELEASE MODE -----'
s.vendored_frameworks = 'Products/release/iphoneos/podLibTest.framework'
end
s.libraries = 'c++'
s.static_framework = true #聲明靜態庫
s.user_target_xcconfig = {'OTHER_LDFLAGS' => '-ObjC'}
s.dependency 'ReactiveCocoa', '2.5'
s.dependency 'SAMKeychain', '1.5.2'
s.dependency 'TMCache', '2.1.0'
s.dependency 'YYCache', '1.0.3'
end