iOS SDK Support Swift Packages


Before starting this, please prepare iOS SDK Deploy Github XCFramework and iOS SDK Sample App import XCFramework,

If you want to know CocoaPods, please check iOS SDK Support CocoaPods.

If you want to know Carthage, please check iOS SDK Support Carthage

スポンサーリンク

Swift Packages

Swift Packages

Create reusable code, organize it in a lightweight way, and share it across Xcode projects and with other developers. (Apple)

SwiftPackage.swift

To prepare SwiftPackage with Binary, we need specific folder structure.

So, I deploy files as a different repository.

The final repository is iOS-Mobile-SDK-SP. (Please check folder structure)

How to make it? Yeah, we can create template from command

Create empty folder and go to folder root.

Run this command

swift package init --type empty

We don’t need some files, so can remove unused folders.

rm -rf Sources Tests

And we need checksum for zip file.

To get checksum use following command.

shasum -a 256 iOSMobileSDK-1.0.0.xcframework.zip

File is upload zip file.

Now, it’s ready to edit file.

Package.swift

// swift-tools-version: 5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

let package = Package(
    name: "iOS-Mobile-SDK-SP",
    platforms: [.iOS(.v15)],
    products: [
        .library(
            name: "iOSMobileSDK",
            targets: ["iOSMobileSDK"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    targets: [
        .binaryTarget(
            name: "iOSMobileSDK",
            url: "https://github.com/DJ110/iOS-Mobile-SDK/releases/download/1.0/iOSMobileSDK-1.0.0.xcframework.zip",
            checksum: "1fe7347c32ae762b65e95d87fdebfd72117640fe498cea909cff5396edefa600"

        ),
    ]
)

This is the final.

iOS support version, and binary URL and checksum are required to update.

Now, it’s ready to use.

Use XCFramework via swiftpackage management

XCode supports swift package import.

From project, File and Add Packages…

Search by github location “https://github.com/DJ110/iOS-Mobile-SDK-SP.git”.

Can find my framework.

Press AddPackage.

We can see dependency.

If you want to see app code, please check this article. iOS SDK Sample App import XCFramework

Application repository is iOSMobileSDKApp (branch feature/swiftpackage)

iOS
スポンサーリンク
Professional Programmer2

コメント