The impact of the coronavirus outbreak, can only stay at home, idle, sorting out the latest code.

1. Create a Framework project

2. Drag in the.h and.m files to compile

Go to Project file -target-Build Phases -headers and drag the.h file you want to expose directly to Public.

3, set up

Navigate to target-build Settings and go to Linking, match-o Type for compiling to static or dynamic libraries.

Build Setting option Build Active Architecture Only Select NO, as the name implies, all architectures are compiled.

At this point, you can theoretically compile the resulting framework and use it, but only in the simulator,

4. Create Aggregate

Create a new target, select Aggregate, and name it yourself.

Add a script,

#! /bin/sh
# Build target name (if a project has multiple targets, it is better to manually specify the target to be packaged, such as TARGET_NAME="framework name ")
TARGET_NAME=${PROJECT_NAME}
if [[ The $1 ]]
then
TARGET_NAME=The $1
fi
UNIVERSAL_OUTPUT_FOLDER="${SRCROOT}/Products/"

Create the output directory and delete the previous framework files
mkdir -p "${UNIVERSAL_OUTPUT_FOLDER}"
rm -rf "${UNIVERSAL_OUTPUT_FOLDER}/${TARGET_NAME}.framework"

Build the Framework for the simulator and the real machine separately
xcodebuild -target "${TARGET_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${TARGET_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build

# copy framework to univer directory
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework" "${UNIVERSAL_OUTPUT_FOLDER}"

Export the final framework to the build directory
lipo -create -output "${UNIVERSAL_OUTPUT_FOLDER}/${TARGET_NAME}.framework/${TARGET_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework/${TARGET_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${TARGET_NAME}.framework/${TARGET_NAME}"

Delete extraneous configuration files generated after compilation
dir_path="${UNIVERSAL_OUTPUT_FOLDER}/${TARGET_NAME}.framework/"
for file in ls $dir_path
do
if [[ ${file}= ~".xcconfig" ]]
then
rm -f "${dir_path}/${file}"
fi
done

If the build folder exists, delete it
if [ -d "${SRCROOT}/build" ]
then
rm -rf "${SRCROOT}/build"
fi

rm -rf "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator" "${BUILD_DIR}/${CONFIGURATION}-iphoneos"

# Open the merged folder
open "${UNIVERSAL_OUTPUT_FOLDER}"
Copy the code

5. Edit and generate Framework.

Select the newly created Aggregate, compile, CMD +B shortcut, and the compiled Framework file will pop up.

6. Application testing

Create a new, simplest Project, which I’ll call HDTest, and drag the generated Framework folder into it

Test any file run finds and pass.

Thanks!!!!!