Create a framework to import into a larger project

In your child project, add a new target by going into the project properties, clicking the + icon and picking Cross-platform > Other > Aggregate.

Go to the target’s tab Build phases and add a run script. Add the following code to the script, and make sure to replace Pixfeature with the framework’s title on line 7:



# make sure the output directory exists

# Step 1. Build Device and Simulator versions
xcodebuild -target "${FW_TARGET}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${FW_TARGET}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build

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

# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then

# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${FW_TARGET}.framework/${FW_TARGET}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FW_TARGET}.framework/${FW_TARGET}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FW_TARGET}.framework/${FW_TARGET}"

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

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

Now you can build this Target, it’ll create a framework file. Finder will open automatically to the output file.

In the parent project, you can embed this framework through the embedded binaries, and you’ll be able to import it in all classes.