Preprocessor flag on Cocoapod podspec

I am creating a framework that uses the preprocessor flag in one of the methods. Something like the following code:

public func heyStuck(overflow: String) {
    #if DEBUG
        print(overflow)
    #else
        print("¯\\_(ツ)_//¯")
    #endif
}

The fact is that I use Cocoapods to import my framework, so in order to define the DEBUG flag for the framework, I have to do something similar in my application subpixel:

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            if config.name != 'Release'
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'DEBUG=1']
        end
        end
    end
end

Is there any way to add this information to the podspec file in order to avoid applications to define this thing in my subfile?

+4
source share
2 answers

I finally got it using the following magic in my podspec file:

s.pod_target_xcconfig = {
  'OTHER_SWIFT_FLAGS[config=Debug]' => '-DDEBUG',
}
+7
source

prefix_header_contents. :

s.prefix_header_contents = #define DEBUG 1
0

Source: https://habr.com/ru/post/1650275/


All Articles