Building a Swift Package with Salesforce Mobile SDK dependency

Viewed 50

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 MobileSync dependency
  • I thought of exposing all the public interfaces for the MobileSync package by importing it from framework header file. So, in the framework Header file of the framework (MobileSyncSPM.h file), added an import for MobileSync.h header file
#import <MobileSync/MobileSync.h>
  • Changed the build settings for the target Build Libraries for Distribution to YES.
  • 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 XCFramework binary 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 XCFramework binary under the Sources on Swift Package.

  • In Package.swift file, I tried to add the XCFramework binary as a binaryTarget as 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.

0 Answers
Related