Swift private framework with backward compatibility with xcode version

This is my first structure using the Swift language and its private structure. It worked as expected until the new Xcode 9.3. After updating the new one Xcode, a problem similar to this one appeared Module compiled with Swift 4.0.3 cannot be imported in Swift 4.1.

After that, only I realized that the framework does not support updating with an automatic version (Xcode / Swift). Whether a single assembly search was detected Universal or Fat Binary Frameworkinstead of a separate assembly for the real device and simulator that I skipped earlier.

UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# Make sure the output directory exists

mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# Next, work out if we're in SIM or DEVICE

xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build

xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build

# Step 2. Copy the framework structure (from iphoneos build) to the universal folder

cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"

# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory

BUILD_PRODUCTS="${SYMROOT}/../../../../Products"

cp -R "${BUILD_PRODUCTS}/Debug-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/." "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"

# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory

lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_PRODUCTS}/Debug-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"

# Step 5. Convenience step to copy the framework to the project directory

cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"

# Step 6. Convenience step to open the project directory in Finder
open "${PROJECT_DIR}"
fi

In Edit Scheme→ Archive→ Post-Action→Run Script

This time I use Swift Compiler - Language→Swift 3.3

And I got the expected result this time too Xcode 9.3withSwift 4.1

Xcode 9.2, , Module compiled with Swift 4.1 cannot be imported in Swift 3.2.3:

, . Xcode 9.2

: Swift Objective C, Min OS iOS 8.0

** **

- compiled with newer version of Swift language (unknown ABI version 0x06) than previous files (4.0) file 'MAC location' for architecture armv7

+4

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


All Articles