Skip to content

EMT-2127-Split-spm-targets-and-add-swift-code. #1502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: 4.0.0.alpha.0
Choose a base branch
from

Conversation

NidhiDixit09
Copy link
Collaborator

@NidhiDixit09 NidhiDixit09 commented Jul 15, 2025

Reference

EMT-2127 - Add swift code and bridging header in SDK
https://branch.atlassian.net/browse/EMT-2127

Summary

-> Converted objective-c class BranchConfigurationController to a swift class ConfigurationController.
-> Split Source folder / SPM Package into three targets - BranchObjCSDK (for core Objective-C classes), BranchSwiftSDK (for Swift classes which uses files from BranchObjCSDK), and BranchSDK (the main public target and which uses files from BranchSwiftSDK as well as BranchObjCSDK).
-> Updated Project workspace and other integration methods for above changes.

Motivation

Converting objective-c code to swift.

Testing Instructions

Branch SDK integration with an app should succeed with all methods of integration (cocoapods, spm, carthage and manual integration).

cc @BranchMetrics/saas-sdk-devs for visibility.

-> Removed DeepLinkDemo, TestDeepLinking and TestHost Apps for the repo.
-> Removed Unit tests from Branch Test Bed App
-> Added Test Host App and Unit tests to BranchSDK Workspace.
Copy link
Contributor

Code Quality new feature

Summary By MatterAI MatterAI logo

🔄 What Changed

This Pull Request introduces significant architectural improvements and refactoring to the Branch SDK, primarily focusing on modularization and modernizing configuration management.

  • GitHub Actions Runner Update: All pre-release QA workflows (.github/workflows/pre-release-qa.yml) have been updated to use macos-15 runners instead of macos-latest across all test jobs (CocoaPods iOS, SPM iOS, Manual iOS, Manual Static iOS, CocoaPods tvOS, Carthage tvOS, Manual tvOS). This ensures tests run on a newer, more stable, and up-to-date build environment. 🚀
  • CocoaPods Specification Update: The BranchSDK.podspec now explicitly supports a wider range of Swift versions (5.0 to 6.0) and includes the new Sources/BranchSDK_Swift and Sources/BranchSDK_ObjC directories in its source files. This prepares the CocoaPods specification for the new modular structure.
  • Swift Package Manager (SPM) Modularization: The Package.swift file has been extensively refactored:
    • The swift-tools-version is updated to 5.9.
    • The package name is changed to ios-branch-deep-linking-attribution.
    • The single BranchSDK target is split into three distinct, modular targets: BranchObjCSDK (for core Objective-C components), BranchSwiftSDK (for Swift components, depending on BranchObjCSDK), and BranchSDK (the main public target, depending on BranchSwiftSDK). This creates a clear separation of concerns and improves dependency management. 📦
  • Configuration Management Migration: The SDK's internal configuration logic has been migrated from the Objective-C BranchConfigurationController to a new Swift-based ConfigurationController.
    • A new Swift file, Sources/BranchSDK_Swift/ConfigurationController.swift, introduces an @objcMembers singleton class (@MainActor public static let shared) that centralizes configuration properties and methods.
    • Existing Objective-C files (BNCRequestFactory.m, Branch.m) have been updated to remove the old Objective-C configuration controller import and now conditionally import and utilize the new Swift ConfigurationController.shared instance. This ensures seamless interop between Objective-C and the new Swift configuration layer. 🔗
  • Header Imports: BranchConstants.h is now publicly imported in Framework/BranchSDK.h and Sources/BranchSDK/Public/BranchSDK.h to support the new modular setup and ensure necessary constants are accessible.

🔍 Impact of the Change

The changes significantly improve the SDK's maintainability, build performance, and future extensibility, especially for projects using Swift Package Manager. By separating Objective-C and Swift codebases into distinct modules, it reduces coupling and clarifies dependencies. The migration to a Swift-based configuration controller modernizes the internal architecture and leverages Swift's features for better type safety and concurrency management (via @MainActor). The updated GitHub Actions runners ensure that CI/CD pipelines are running on current and supported environments, leading to more reliable builds. This refactoring lays a stronger foundation for future development.

📁 Total Files Changed

7 files were changed in this Pull Request.

🧪 Test Added

No new explicit test files were added in this PR. However, the existing pre-release QA workflows in .github/workflows/pre-release-qa.yml will now run on macos-15, implicitly testing the changes in the new environment. These workflows cover:

  • verify-cocoapods-iOS: Tests the SDK integration via CocoaPods on iOS.
  • verify-SPM-iOS: Tests the SDK integration via Swift Package Manager on iOS.
  • verify-manually-with-xcframework-iOS: Tests manual integration with XCFrameworks on iOS.
  • verify-manually-with-StaticFramework-iOS: Tests manual integration with Static Frameworks on iOS.
  • verify-cocoapods-tvOS: Tests the SDK integration via CocoaPods on tvOS.
  • verify-carthage-tvOS: Tests the SDK integration via Carthage on tvOS (currently skipped due to being broken).
  • verify-manually-with-xcframework-tvOS: Tests manual integration with XCFrameworks on tvOS.

These comprehensive existing tests will validate that the architectural changes and configuration migration do not introduce regressions and that the SDK continues to function correctly across various integration methods.

🔒Security Vulnerabilities

No new security vulnerabilities were detected. The changes primarily involve refactoring and build system updates, which do not introduce new attack surfaces. The use of @MainActor for the ConfigurationController singleton helps ensure thread-safe access to configuration data, which is a good practice for preventing race conditions and maintaining data integrity.

Tip

Quality Recommendations

  1. Consider adding dedicated unit tests for the ConfigurationController to ensure its internal logic and data aggregation methods (branchKeyInfo, featureFlagsInfo, frameworkIntegrationInfo) function as expected, separate from integration tests.

  2. While @MainActor ensures thread-safe access to properties, if getConfiguration() or its internal helper methods are frequently called from background threads, evaluate if any performance implications arise from potential main thread blocking, or if parts of the ConfigurationController could be made nonisolated if they are purely computational and don't touch @MainActor state directly.

  3. For SPM users, it would be beneficial to include a brief migration guide or release notes detailing the new modular structure and any potential changes required for their Package.swift files to adopt the new BranchSDK, BranchSwiftSDK, and BranchObjCSDK targets.

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant GH_Actions as GitHub Actions
    participant ObjC_SDK as BranchSDK (Objective-C)
    participant Swift_SDK as BranchSwiftSDK
    participant Config_Controller as ConfigurationController (Swift)

    GH_Actions->>GH_Actions: Update runner to macos-15
    Note over GH_Actions: All test jobs (CocoaPods, SPM, Manual) will run on macos-15

    App->>ObjC_SDK: Initialize Branch SDK
    Note over ObjC_SDK: Calls from Branch.m, BNCRequestFactory.m

    ObjC_SDK->>+Config_Controller: ConfigurationController.shared
    Note over Config_Controller: Accesses singleton instance (via @MainActor)

    ObjC_SDK->>Config_Controller: setBranchKeySource(source: String)
    ObjC_SDK->>Config_Controller: setDeferInitForPluginRuntime(value: Bool)
    ObjC_SDK->>Config_Controller: setCheckPasteboardOnInstall(value: Bool)

    ObjC_SDK->>+Config_Controller: getConfiguration()
    Config_Controller->>Config_Controller: branchKeyInfo()
    Config_Controller->>Config_Controller: featureFlagsInfo()
    Config_Controller->>Config_Controller: frameworkIntegrationInfo()
    Config_Controller-->>-ObjC_SDK: return configDictionary

    ObjC_SDK-->>App: SDK Initialized / Request Processed
Loading

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@NidhiDixit09 NidhiDixit09 changed the title Emt 2127 split spm targets a EMT-2127-Split-spm-targets-and-add-swift-code. Jul 15, 2025
@NidhiDixit09 NidhiDixit09 changed the base branch from master to 4.0.0.alpha.0 July 15, 2025 16:14
Copy link
Contributor

Note

PR Review Skipped

PR review skipped as no relevant changes found due to large diff hunk OR part of a non-reviewable file.

📄Files skipped in review
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
  • undefined: undefined
💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@NidhiDixit09 NidhiDixit09 marked this pull request as ready for review July 16, 2025 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants