I am trying to build a Swift Package which depends on Salesforce Mobile SDK (MobileSync library). I didn't find any Swift Package for Salesforce mobile SDK yet, so I was trying to use the MobileSync pod.
What I tried?
These are the steps I followed
- I created a new framework project (let's called it
MobileSyncSPM) - Initialized pod file and added
MobileSyncdependency - I thought of exposing all the public interfaces for the
MobileSyncpackage by importing it from framework header file. So, in the framework Header file of the framework (MobileSyncSPM.hfile), added an import forMobileSync.hheader file
#import <MobileSync/MobileSync.h>
- Changed the build settings for the target
Build Libraries for DistributiontoYES. - Archived the workspace project
xcodebuild archive \
-workspace MobileSyncSPM.xcworkspace \
-scheme MobileSyncSPM \
-configuration Debug \
-destination 'generic/platform=iOS' \
-archivePath './build/MobileSyncSPM.framework-iphoneos.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
xcodebuild archive \
-workspace MobileSyncSPM.xcworkspace \
-scheme MobileSyncSPM \
-configuration Debug \
-destination 'generic/platform=iOS Simulator' \
-archivePath './build/MobileSyncSPM.framework-iphonesimulator.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
- Generated
XCFrameworkbinary for the archives
xcodebuild -create-xcframework \
-framework './build/MobileSyncSPM.framework-iphoneos.xcarchive/Products/Library/Frameworks/MobileSyncSPM.framework' \
-framework './build/MobileSyncSPM.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/MobileSyncSPM.framework' \
-output './build/MobileSyncSPM.xcframework'
I added the
XCFrameworkbinary under theSourceson Swift Package.In
Package.swiftfile, I tried to add theXCFrameworkbinary as abinaryTargetas follows -
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "MyUtils",
dependencies: [
.byName(name: "MobileSyncSPM")
]
),
.binaryTarget(name: "MobileSyncSPM", path: "Sources/MyUtils/MobileSyncSPM.xcframework"),
.testTarget(
name: "MyUtilsTests",
dependencies: ["MyUtils"]
),
]
- The Swift Package builds successfully with the binary target.
The problem occurs when I try to import the XCFramework library (MobileSyncSPM) from inside the Swift Package.
So inside a swift file under the swift package, if I add the following import
import MobileSyncSPM
I get the error that says
Could not build Objective-C module MobileSyncSPM
Looking forward to your suggestions on fixing the issue.