我正在使用来自这个问题的ank解决方案:Cocoapods: turning MagicalRecord logging off在我将CocoaPods更新到最新版本(0.38.2)之前曾经有效。现在每当我运行pod install
命令时,它都会返回几个错误。
供参考,以下是ank(link)共享的原始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
我遇到的第一个问题是需要在Podfile上用project
替换pods_project
,所以我做了。
但让我陷入困境的是它无法识别build_configurations
语句,正如您在控制台错误中看到的那样:
...
Generating Pods project
[!] An error occurred while processing the post-install hook of the Podfile.
undefined method `build_configurations' for nil:NilClass
...
我已经搜索过该问题,但无法从SO或gitHub或其他网站找到适合它的解决方案。我相信可能需要进行一些更改才能使代码片段在此版本的CocoaPods上再次运行,因此我想知道是否有人提出了解决此问题的方法,或者是否有另一种方法可以关闭loggin for MagicalRecord(BTW我使用的是2.2版本。)
这是我的Podfile的最后一部分:
post_install do |installer|
target = installer.pods_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
任何帮助都将受到广泛赞赏:)
答案 0 :(得分:1)
我发现您需要使用"MagicalRecord"
而不是"Pods-MagicalRecord"
,在post_install中添加以下行:
puts installer.pods_project.targets
我的解决方案代码:
# Turn off Magical Record logging in debug mode - in release mode it is off by default
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;
# Uncomment one matching your version
#s.push('MR_ENABLE_ACTIVE_RECORD_LOGGING=0') if config.to_s == "Debug"; # MagicalRecord < 2.3
#s.push('MR_LOGGING_DISABLED=1') if config.to_s == "Debug"; # MagicalRecord 2.3+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = s
end