最近一个项目用swift开发的,需要用到数据库,查了一下,看到realm评价很高,就想试试,没想到各种踩坑,下面将这些坑记录下来,希望对大家有帮助。
1.集成realm后,第一次编译可以通过,但运行的时候,报下面这个错误:
解决方法:TARGETS -> Build Phases 点击坐上角+,add copy Files Phase,然后将你引入的framework添加进去,就可以运行通过了。
2.在打包上架的时候,进行到最后一步,会出现下面一系列错误:
解决办法 :TARGETS -> Build Phases ->点击加号选择 New Run Script Phase ,然后粘贴下面的代码,就可以了
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
3.如果未加入上一步的操作,在打包测试的时候,会遇到下面的错误
我当时在TARGETS->Build Settings中将Enable Bitcode改为No就可以了,后面加入第二个错误的解决代码,发现改回YES,也可以正常运行通过,并且打包成功。
Realm数据库是很好用,比我以前自己写sql语句方便多了,但是坑也不少,一不小心就踩坑了,需要学习的地方还有很多。