除了本地豆荚之外,我怎样才能消除所有豆荚的警告?

hfo*_*sli 20 cocoapods

我假设有些东西

post_install do |installer|

  # Debug symbols
  installer.pod_project.targets.each do |target|
    target.build_configurations.each do |config|
      if ? == ?
        config.build_settings['?'] = '?'
      end
    end
  end

end
Run Code Online (Sandbox Code Playgroud)

小智 7

我今天遇到了类似的问题,并根据依赖项的复杂性找到了两种方法来实现此目的。

第一种方法很简单,如果您的本地开发 pod 位于主 pod 文件中并且未嵌套在另一个依赖项中,则应该可以使用。基本上像往常一样禁止所有警告,但在每个本地 Pod 上指定 false:

inhibit_all_warnings!

pod 'LocalPod', :path => '../LocalPod', :inhibit_warnings => false
pod 'ThirdPartyPod',
Run Code Online (Sandbox Code Playgroud)

第二种更全面且适用于复杂嵌套依赖项的方法是创建本地 Pod 的白名单,然后在安装后期间禁止不属于白名单的任何 Pod 发出警告:

$local_pods = Hash[
  'LocalPod0' => true,
  'LocalPod1' => true,
  'LocalPod2' => true,
]

def inhibit_warnings_for_third_party_pods(target, build_settings)
  return if $local_pods[target.name]
  if build_settings["OTHER_SWIFT_FLAGS"].nil?
    build_settings["OTHER_SWIFT_FLAGS"] = "-suppress-warnings"
  else
    build_settings["OTHER_SWIFT_FLAGS"] += " -suppress-warnings"
  end
  build_settings["GCC_WARN_INHIBIT_ALL_WARNINGS"] = "YES"
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      inhibit_warnings_for_third_party_pods(target, config.build_settings)
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

现在,这只会抑制第 3 方依赖项,但会在任何本地 pod 上保留警告。


Swi*_*ect 2

Podfile 解决方案

虽然ignore_all_warnings是全有或全无的命题,但您可以:inhibit_warnings => true在 Podfile 中的任何单个 pod 上。

# Disable warnings for each remote Pod
pod 'TGPControls', :inhibit_warnings => true

# Do not disable warnings for your own development Pod
pod 'Name', :path => '~/code/Pods/' 
Run Code Online (Sandbox Code Playgroud)

  • 我知道这个选项,但这不是我想要的。我想动态地执行此操作,因为我不想手动列出每个依赖项和从属依赖项来消除这些警告。 (2认同)