问题
I have an XCode workspace managed by Cocoapod
with a few dependencies to external libraries. One of them, MTDates, extends NSDate
and NSDateComponents
with either prefixed methods, or non-prefixed if a certain preprocessor macro is defined (which is what I want).
There are a few places where I can put the preprocessor macro definition in order to have the compiled library provide the non-prefixed methods, but all seem to be reset as soon as I ask Cocoapod
to update the project, which leads me to think that these configs are driven by the pod spec. These include :
- The pod's target build settings
- The pod's private
.xcconfig
file in Cocoapod's Targets Support Files
Changing the pod's spec would require to manage my own version of the library, whereby losing the ability for cocoapods
to update it when a new version comes around. So my question is: is there a way to specify a preprocessor macro for a cocoapod
dependency, without forking the pod and changing the pod's spec itself?
Edit:
There is an open issue about this, that seem to be just around the corner.
回答1:
This functionality is now available. Here is an example of what you could put at the bottom of your Podfile to add a macro based on a specific configuration.
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
if target.name == "Pods-TweaksBuildConfigurationsDemo-Tweaks"
target.build_configurations.each do |config|
if config.name == 'QA'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'FB_TWEAK_ENABLED=1']
end
end
end
end
end
回答2:
Looking at Cocoapods documentation, I don't think this is possible just yet, I think what you can do is to copy the pod spec - make the changes you want (e.g s.prefix_header_contents = #define symbolToDefine
) and then add it to your local specs with a different name, and use that in your pod file. When a new version comes out unfortunately, you'd have to go in and change the tag number (and other stuff depending on the changes).
回答3:
as you mentioned 'The pod's private .xcconfig file in Cocoapod's Targets Support Files', i do this resolved my problem.
s.xcconfig = {'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1 IOS=1' }
来源:https://stackoverflow.com/questions/17908569/specifying-preprocessor-macros-for-a-cocoapod-dependency-without-forking-it