Is there a way to conditionally define a Podspec property depending on static or dynamic usage?
I was able to use an Xcode environment variable (PACKAGE_TYPE
) in conjunction with a pre-compilation Run Script build phase to dynamically produce a header to import, which in turn makes the correct generated Swift Header import.
generate-swift-import-header.sh
#!/bin/sh
[[ "${PACKAGE_TYPE}" = "com.apple.package-type.wrapper.framework" ]] \
&& SWIFTIMPORT="<${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}-Swift.h>" \
|| SWIFTIMPORT="\"${PRODUCT_MODULE_NAME}-Swift.h\""
if [ -z "$PODS_TARGET_SRCROOT" ]; then
PODS_TARGET_SRCROOT=${SOURCE_ROOT}
echo "Building in Xcode instead of CocoaPods. Overriding PODS_TARGET_SRCROOT with SOURCE_ROOT"
fi
_Import_text="
#ifndef GeneratedSwiftImport_h
#define GeneratedSwiftImport_h
#import ${SWIFTIMPORT}
#endif /* GeneratedSwiftImport_h */
"
echo "$_Import_text" > ${PODS_TARGET_SRCROOT}/Source/GeneratedSwiftImport.h
Podspec update
s.script_phases = { :name => "Generate UnzipKit Swift Header",
:script => "\"${PODS_TARGET_SRCROOT}\"/Scripts/generate-swift-import-header.sh",
:execution_position => :before_compile }
Library source
I replaced my conditional import with this:
#import "GeneratedSwiftImport.h"
I also ignored the GeneratedSwiftImport.h
file in Git.
How to build dylib in XCode?
object files (.o) could be extracted from archive file (.a) and then packed in .dylib with libtool or gcc
Related Topics
Parse.Com Pfquery Order by Time (Swift)
Image Disappears When Styling Class to Make a Round Image
How to Display an Image by an API Url? Swift
Unexpected Non-Void Return Value in Void Function Swift 4 Using JSON Serialisation
Swift: How to Get Information for an Application Which Is Not Running
Replacing Multiple Different Occurences with Multiple Different Replacements - Swift4.2
Stopping Timer at Defined Amount of Time in Swift
Swiftui Tabview Gives an Error Message During Add/Delete the Element of Coredata
How to Make Struct Lazylist in Swiftui
Can't Use 'Shape' as Type in Swiftui
How to Inject .Environmentobject() in Watchos6
How to Change the Appearance of the Datepicker in the Swiftui Framework to Only Months and Years
How to Call a Func Within a Closure
Ios13 Uialertcontroller with Custom View & Preferredstyle as Actionsheet Grayscale All Colors