有時候我們需要重新設置 Pods-xxx.xcconfig
的 OTHER_LDFLAGS
標志
可以使用如下腳本
# update xcconfig property
def update_xcconfig(xcconfig_path, key, value)
# read from xcconfig to build_settings dictionary
build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.delete!("\n").split(/\s*=\s*/, 2)}.flatten]
# modify key
if build_settings.has_key?(key)
build_settings[key] << value
else
build_settings[key] = value
end
# write build_settings dictionary to xcconfig
File.open(xcconfig_path, "w+") {|file|
build_settings.each do |k, v|
file.puts "#{k} = #{v}"
end
}
end
# post_install hook
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# 添加額外的 OTHER_LDFLAGS
xcconfig_path = config.base_configuration_reference.real_path
update_xcconfig(xcconfig_path, 'OTHER_LDFLAGS', ' -ObjC')
end
end
end
非常的簡單實用,
參考 How can I modify OTHER_LDFLAGS via CocoaPods post-install hook?