What is interesting here is the two framework folders openmp.xcframework
and sherpa-ncnn.xcframework.
All other folders can be safely removed. We only need the two framework folders.
In the following, we describe the content in these two framework folders.
We provide a bridging header for you: SherpaNcnn-Bridging-Header.h. All you need is to add this file to your iOS project
and click BuildSettings->SwiftCompiler-General and set Objective-CBridgingHeader
to ${PROJECT_DIR}/../../swift-api-examples/SherpaNcnn-Bridging-Header.h. See
the screenshot below for reference:
Fig. 30 Screenshot for setting the bridging header
We list the content of the bridging header below for reference:
After adding the bridging header to your iOS project, Xcode will complain
it cannot find sherpa-ncnn/c-api/c-api.h. The fix is to add the path
build-ios/sherpa-ncnn.xcframework/Headers to HeaderSearchPaths by changing
BuildSettings->SearchPaths->HeaderSearchPaths, as is shown in the
following screenshot:
Fig. 31 Screenshot for setting the header search paths
Hint
Instead of using an absolute path, we use
${PROJECT_DIR}/../../build-ios/sherpa-ncnn.xcframework/Headers/
For instance, my sherpa-ncnn is downloaded to
/Users/fangjun/open-source/sherpa-ncnn and the path to sherpa-ncnn.xcframework
is /Users/fangjun/open-source/sherpa-ncnn/build-ios/sherpa-ncnn.xcframework.
The value of PROJECT_DIR is
/Users/fangjun/open-source/sherpa-ncnn/ios-swift/SherpaNcnn, so
we can use ${PROJECT_DIR}/../../build-ios/sherpa-ncnn.xcframework/Headers/.
Also note that PROJECT_DIR is a pre-defined variable in Xcode.
Please also add SherpaNcnn.swift
to your iOS project, which is a utility to make it easier to access functions from the bridging header.
The next thing is to add openmp.xcframework and sherpa-ncnn.xcframework
as dependencies to you iOS project. Select BuildPhases->LinkBinarywithLibraries
and then click + to add sherpa-ncnn.xcframework and openmp.xcframework.
See the screenshot below for reference:
Fig. 32 Screenshot for adding a framework to your project
Hint
After clicking +, please select AddOther...->AddFiles.., and then
add the path to sherpa-ncnn.xcframework.
One more thing you need to do after adding the framework is to setup the framework
search path. Click BuildSettings->SearchPaths->FrameworkSearchPaths
and add the path to build-ios/. See the screenshot below:
Fig. 34 Screenshot for setting framework search paths
If you encounter link errors about the C++ standard library, please add
-lc++ to link against libc++ by clicking BuildSettings->Linking->OtherLinkerFlags
and adding -lc++. See the screenshot below for reference:
Fig. 35 Screenshot for adding -lc++ to linker flags
That is all you need to add sherpa-ncnn to your iOS project.