4

I'm using ank's solution from this SO question: Cocoapods: turning MagicalRecord logging off which used to work well before I updated CocoaPods to the latest version (0.38.2). Now whenever I run the pod install command it returns several errors.

For reference, here is the original Podfile snippet shared by ank (link):

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

The first problem I encounter was that project needed to be replaced with pods_project on the Podfile, so I did.

But the one that got me stuck is that it doesn't recognize the build_configurations statement, as you can see on the console error bellow:

...
Generating Pods project
[!] An error occurred while processing the post-install hook of the Podfile.

undefined method `build_configurations' for nil:NilClass
...

I have googled the issue but could not find a working solution for it neither from SO nor gitHub or other sites. I believe there might be some more changes needed in order for the snippet to work again on this version of CocoaPods so I would like to know if anyone have come up with a solution for this problem or if there is another way to turn off loggin for MagicalRecord (BTW I'm using version 2.2).

Here is the last portion of my 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

Any help will be widely appreciated :)

Community
  • 1
  • 1
lmt
  • 811
  • 1
  • 11
  • 27
  • any success on that one? – Georg Sep 17 '15 at 12:12
  • Hi @Georg sorry but no success so far. I just removed the above code so I could finish the pod install command and have the .xcworkspace file generated, but I still couldn't find a way to turn loggin off with CocoaPods 0.38 – lmt Sep 17 '15 at 16:12

1 Answers1

1

I found out that you need to use "MagicalRecord" instead of "Pods-MagicalRecord" by adding following line in post_install:

puts installer.pods_project.targets

My working solution code:

# 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
Exec
  • 26
  • 2