项目'Pods' - 打开整个模块优化

Jon*_*ano 22 xcode cocoapods swift xcode9

在Xcode 9中,我得到了一个可可豆荚项目的以下建议: 建议

它有什么作用?而且,我应该打开它,还是会破坏它?

Mik*_*ler 19

您可以在每次运行时自动启用此功能,方法pods install是将以下post_install脚本添加到您的结尾Podfile.

post_install do |installer| 
  installer.pods_project.build_configurations.each do |config|
    if config.name == 'Release'
      config.build_settings['SWIFT_COMPILATION_MODE'] = 'wholemodule'
    end    
  end
end
Run Code Online (Sandbox Code Playgroud)

在旧版本的Xcode中,您将需要:

post_install do |installer| 
  installer.pods_project.build_configurations.each do |config|
    if config.name == 'Release'
      config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Owholemodule'
    else
      config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
    end    
  end
end
Run Code Online (Sandbox Code Playgroud)


Law*_*iet 11

使用整个模块优化允许编译器查看模块中的所有源文件.这使编译速度变慢,但即使它们位于不同的源文件中,也允许它优化泛型函数.您可以在最终测试运行中看到这一点,其中本地和外部函数定义的执行时间现在都相同.

总之,如果您不介意额外的编译时间,请尝试为发布版本启用整体模块优化.

源代码应该为您提供有关整个模块优化的更多见解

对Xcode所做的Pods项目的任何更改都会在您下次运行时被吹走,pod install因此必须在Cocoapods内进行更新以消除此警告.有一个关于这个的讨论在这里.

短期解决方案是添加Mike建议post_install脚本.