Skip to content

Instantly share code, notes, and snippets.

@roothybrid7
Created March 26, 2014 06:30
Show Gist options
  • Save roothybrid7/9777804 to your computer and use it in GitHub Desktop.
Save roothybrid7/9777804 to your computer and use it in GitHub Desktop.
CocoaPodsでアプリ側ターゲットのbuild_settingsを変更する方法 ref: http://qiita.com/roothybrid7/items/403b2fb453b1674102a4
#ifndef APP_TESTING
// テスト以外のときだけ実行する処理
// 広告SDKとかが勝手にブラウザへ飛ばす処理とか
#endif
TESTING_TARGETS = %w[AppTests AppIntegrationTests]
post_install do |installer|
# アプリ側のxcode projectを開く
Xcodeproj::Project.open('App.xcodeproj').tap do |project|
targets = project.targets.find_all do |target|
TESTING_TARGETS.include?(target.name)
end
# Test用macro定義
targets.each do |target|
target.build_configurations.each do |config|
if config.name == "Debug"
preprocessor_definitions = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] || ['$(inherited)']
preprocessor_definitions = [preprocessor_definitions] unless preprocessor_definitions.instance_of?(Array)
preprocessor_definitions.push('APP_TESTING=1').uniq!
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = preprocessor_definitions
end
end
end
project.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment