※下記のTipsは CocoaPods
を使用している前提です。
App Icon や Launch Imageは簡単にターゲット毎に反映できますが、
.xcassets
内の画像はうまく反映されないことがあります。
その際の対処方法について
開発環境
Xcode 7.2
Swift 2.0
CocoaPods 0.39.0
Tips
1 ) 分岐用に xcassets
を複数作成
一例
image.xcassets //=> 本番用
image_dev.xcassets //=> dev用
※一部の画像だけを分岐させたい場合は共通画像用の「xcassets」も作成するなど
プロジェクト毎にカスタマイズを
2) Target Memebershipを分岐
3) Podfile内に下記を追記して、 pod install
Podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
folder_path = "Pods/Target\\ Support\\ Files/Pods/Pods"
%x~ if [ ! -f #{folder_path}-resources.sh.bak ]; then cp #{folder_path}-resources.sh #{folder_path}-resources.sh.bak; fi ~
%x~ sed '/WRAPPER_EXTENSION/,/fi\\n/d' #{folder_path}-resources.sh > #{folder_path}-resources.sh.temp ~
%x~ sed '/*.xcassets)/,/;;/d' #{folder_path}-resources.sh.temp > #{folder_path}-resources.sh ~
%x~ rm #{folder_path}-resources.sh.temp ~
end
end
以上です。これでターゲット毎に.xcassets
内の画像が反映されます。
Pod install時にやってること
Pods > Targets Support Files > Pods > Pods-resources.shの
下記の箇所が削除されます(コメントアウトしてるところ)