From c00ee39d6e85f3592a7b35ca5b1bec76327d92e0 Mon Sep 17 00:00:00 2001 From: Duong Dao Date: Thu, 18 Jun 2026 11:26:33 +0700 Subject: [PATCH 1/2] Added support for SPM --- .claude/settings.json | 12 +++++ EmbedFramework/AdaWebHostViewController.swift | 16 +------ EmbedFramework/Bundle+Ada.swift | 39 ++++++++++++++++ EmbedFramework/OfflineViewController.swift | 14 +----- Package.swift | 44 +++++++++++++++++++ 5 files changed, 98 insertions(+), 27 deletions(-) create mode 100644 .claude/settings.json create mode 100644 EmbedFramework/Bundle+Ada.swift create mode 100644 Package.swift diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..5ddb3f4 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,12 @@ +{ + "permissions": { + "allow": [ + "Bash(swift --version)", + "Bash(swift package *)", + "Bash(echo \"exit=$?\")", + "Bash(xcodebuild -list)", + "Bash(ln -s /Users/ddao/Projects/Xcode/ada-spm/Package.swift /tmp/ada-spm-build/Package.swift)", + "Bash(ln -s /Users/ddao/Projects/Xcode/ada-spm/EmbedFramework /tmp/ada-spm-build/EmbedFramework)" + ] + } +} diff --git a/EmbedFramework/AdaWebHostViewController.swift b/EmbedFramework/AdaWebHostViewController.swift index 460f7f0..cf806c3 100644 --- a/EmbedFramework/AdaWebHostViewController.swift +++ b/EmbedFramework/AdaWebHostViewController.swift @@ -11,20 +11,8 @@ import WebKit class AdaWebHostViewController: UIViewController { static func createWebController(with webView: WKWebView) -> AdaWebHostViewController { - let bundle = Bundle(for: AdaWebHostViewController.self) - - var storyboard:UIStoryboard - - // Loads the resource_bundle if available (Cocoapod) - if (bundle.path(forResource: "AdaEmbedFramework", ofType: "bundle") != nil){ - let frameworkBundlePath = bundle.path(forResource: "AdaEmbedFramework", ofType: "bundle")! - let frameworkBundle = Bundle(path: frameworkBundlePath) - storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: frameworkBundle) - } else { - // Used for if SDK was manually imported - storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: bundle) - } - + let storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: .ada) + guard let viewController = storyboard.instantiateInitialViewController() as? AdaWebHostViewController else { fatalError("This should never, ever happen.") } viewController.webView = webView return viewController diff --git a/EmbedFramework/Bundle+Ada.swift b/EmbedFramework/Bundle+Ada.swift new file mode 100644 index 0000000..ff1a14d --- /dev/null +++ b/EmbedFramework/Bundle+Ada.swift @@ -0,0 +1,39 @@ +// +// Bundle+Ada.swift +// EmbedFramework +// +// Resolves the bundle that holds AdaEmbedFramework's resources +// (storyboard, asset catalog) across every integration method: +// Swift Package Manager, CocoaPods, Carthage, and manual import. +// + +import Foundation + +extension Bundle { + /// The bundle containing AdaEmbedFramework's resources. + /// + /// - Under SPM, resources live in the generated `Bundle.module`. + /// - Under CocoaPods/Carthage, they live in a nested + /// `AdaEmbedFramework.bundle` inside the framework bundle. + /// - When manually imported, they sit directly in the framework bundle. + static let ada: Bundle = { + #if SWIFT_PACKAGE + return Bundle.module + #else + let moduleName = String(reflecting: BundleToken.self) + .components(separatedBy: ".") + .first + let bundle = Bundle(for: BundleToken.self) + guard + let moduleName = moduleName, + let path = bundle.path(forResource: moduleName, ofType: "bundle"), + let subbundle = Bundle(path: path) + else { return bundle } + return subbundle + #endif + }() +} + +// MARK: - + +private final class BundleToken {} diff --git a/EmbedFramework/OfflineViewController.swift b/EmbedFramework/OfflineViewController.swift index 6e59565..1b19b20 100644 --- a/EmbedFramework/OfflineViewController.swift +++ b/EmbedFramework/OfflineViewController.swift @@ -16,19 +16,7 @@ class OfflineViewController: UIViewController { var retryBlock: (() -> Void)? static func create() -> OfflineViewController? { - let bundle = Bundle(for: OfflineViewController.self) - - var storyboard:UIStoryboard - - // Loads the resource_bundle if available (Cocoapod) - if (bundle.path(forResource: "AdaEmbedFramework", ofType: "bundle") != nil){ - let frameworkBundlePath = bundle.path(forResource: "AdaEmbedFramework", ofType: "bundle")! - let frameworkBundle = Bundle(path: frameworkBundlePath) - storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: frameworkBundle) - } else { - // Used for if SDK was manually imported - storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: bundle) - } + let storyboard = UIStoryboard(name: "AdaWebHostViewController", bundle: .ada) return storyboard.instantiateViewController(withIdentifier: "OfflineViewController") as? OfflineViewController } diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..86bfa84 --- /dev/null +++ b/Package.swift @@ -0,0 +1,44 @@ +// swift-tools-version:5.5 +import PackageDescription + +// Generated from AdaEmbedFramework.podspec (version 1.8.0). +// The target is named "AdaEmbedFramework" so it matches the +// customModule="AdaEmbedFramework" references inside the storyboard. +let package = Package( + name: "AdaEmbedFramework", + // podspec declares ios 10.0; SPM resource bundles are only reliable on iOS 11+. + platforms: [ + .iOS(.v11) + ], + products: [ + .library( + name: "AdaEmbedFramework", + targets: ["AdaEmbedFramework"] + ) + ], + targets: [ + .target( + name: "AdaEmbedFramework", + // Mirrors podspec source_files = "EmbedFramework/**/*.swift" + path: "EmbedFramework", + // Non-Swift files that are not part of the shipped resources. + exclude: [ + "Info.plist", + "EmbedFramework.h", + "AdaEmbed.html", + "EmbedTest.html", + "EmbedView.xib", + "OfflineView.xib", + "View.xib", + "en.lproj" + ], + // Mirrors podspec resource_bundles (xcassets + storyboard). + resources: [ + .process("Assets.xcassets"), + .process("AdaWebHostViewController.storyboard") + ] + // Swift 5 language mode (podspec swift_version = '5.0') is the + // default for swift-tools-version:5.5, so no extra setting is needed. + ) + ] +) From 00b2506698e3a6bb72bd52a1f809ab4eca6a4521 Mon Sep 17 00:00:00 2001 From: Duong Dao Date: Thu, 18 Jun 2026 11:28:10 +0700 Subject: [PATCH 2/2] Added support for SPM --- .claude/settings.json | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .claude/settings.json diff --git a/.claude/settings.json b/.claude/settings.json deleted file mode 100644 index 5ddb3f4..0000000 --- a/.claude/settings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "permissions": { - "allow": [ - "Bash(swift --version)", - "Bash(swift package *)", - "Bash(echo \"exit=$?\")", - "Bash(xcodebuild -list)", - "Bash(ln -s /Users/ddao/Projects/Xcode/ada-spm/Package.swift /tmp/ada-spm-build/Package.swift)", - "Bash(ln -s /Users/ddao/Projects/Xcode/ada-spm/EmbedFramework /tmp/ada-spm-build/EmbedFramework)" - ] - } -}