Cocoapods:关闭MagicalRecord

And*_*sky 39 xcode objective-c ios cocoapods magicalrecord

关闭MagicalRecord注销需要在项目首次包含之前进行#define,但是对于由Cocoapods管理的项目,我无权在Pods项目中添加#define.在这种情况下如何完全关闭注销?

花了几个小时找出办法,在这里张贴,希望它能帮助别人.

编辑:这不是重复,因为它讨论了在Cocoapods下关闭日志

And*_*sky 79

您可以使用post_install挂钩来修改几乎任何构建设置.只需将此代码添加到您的Podfile:

post_install do |installer|
  target = installer.project.targets.find{|t| t.to_s == "Pods-MagicalRecord"}
    target.build_configurations.each do |config|
        s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
        s = [ '$(inherited)' ] if s == nil;
        s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug";
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
    end
end
Run Code Online (Sandbox Code Playgroud)

请注意,这将仅禁用调试配置中的日志记录 - 默认情况下,在发布配置中禁用日志记录.

  • 由于我很少运行`pod update`,我只是将它添加到我的pods pch文件中. (2认同)
  • Re:拼写错误 - 你可以把`s || = ['$(inherited)']`. (2认同)

Cod*_*Ray 13

就我而言,我正在构建一个依赖于MagicalRecord的库.我不希望我的用户必须在他们的Podfile中添加post_install以使嘈杂的日志记录静音,所以我将其添加到我的podspec中.

  s.prefix_header_contents = '#define MR_ENABLE_ACTIVE_RECORD_LOGGING 0'
Run Code Online (Sandbox Code Playgroud)

这会自动将此#define语句添加到Pods-prefix.pch,这会使使用我的pod的项目中的MagicalRecord日志记录静音.


Iva*_*uel 5

我为那些使用新的cocoapods版本以及MagicalRecord 2.3.0的人更新了ank的答案:

post_install do |installer|
  target = installer.pods_project.targets.find{|t| t.to_s == "MagicalRecord"}
  target.build_configurations.each do |config|
    s = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
    s = [ '$(inherited)' ] if s == nil;
    s.push('MR_LOGGING_DISABLED=1') if config.to_s == "Debug";
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
  end
end
Run Code Online (Sandbox Code Playgroud)

变化:

  • project 改名为 pods_project
  • 目标已Pods-MagicalRecord重命名为MagicalRecord
  • MR_ENABLE_ACTIVE_RECORD_LOGGING重命名为MR_LOGGING_DISABLED和值已更改01