Skip to content

Commit 618e87d

Browse files
committed
Implement Swift Concurrency for iOS Branch SDK (EMT-2309)
This commit introduces modern Swift Concurrency patterns to the iOS Branch SDK, mirroring the Android Kotlin Coroutines implementation. The changes enable async/await request processing, actor-based thread safety, and structured concurrency throughout the SDK. ## Swift Concurrency Implementation Added three core Swift files using modern concurrency patterns: - `BranchRequestOperation.swift`: Actor-isolated async operation for processing Branch server requests with structured concurrency, automatic main thread dispatching for callbacks, and session validation matching Android's implementation - `BranchRequestQueue.swift`: Actor-based request queue with serial execution, async/await API, and thread-safe queue management replacing manual NSOperationQueue patterns - `ConfigurationController.swift`: Swift configuration management with async initialization and proper error handling Architecture parallels to Android: - Android: CoroutineScope + Channel → iOS: Actor + AsyncStream - Android: Dispatchers.IO → iOS: Task.detached - Android: Dispatchers.Main → iOS: MainActor ## Swift Package Manager (SPM) Integration Updated Package.swift to define dual-target architecture: - `BranchObjCSDK`: Core Objective-C framework with all existing functionality - `BranchSDK`: Swift wrapper exposing async/await APIs and importing BranchObjCSDK This enables seamless Swift integration while maintaining full Objective-C compatibility. ## Objective-C Bridge Enhancements Modified `BNCServerRequestOperation.m` to support Swift interop: - Added Swift availability checks (@available decorators) - Integrated async callback completion handling - Maintained backward compatibility with existing Objective-C code Updated `BNCServerRequestQueue.m` and `BNCRequestFactory.m` for improved Swift interaction. ## Public API Visibility Changes Moved `BNCConfig.h` from Private to Public headers to enable SPM package visibility. Added `BranchConstants.h` and `BranchConstants.m` to public BranchSDK directory for proper module exposure. ## Test Infrastructure Updates Updated 16 test files to use modular imports: - Changed from `#import "Branch.h"` to `@import BranchSDK` - Updated bridging headers for Swift/Objective-C interop - Modified test schemes to support SPM package dependencies Test files updated: - BNCAPIServerTest.m, BNCODMTests.m, BNCPasteboardTests.m - BNCPreferenceHelperTests.m, BranchActivityItemTests.m - BranchClassTests.m, BranchLoggerTests.m, BranchQRCodeTests.m - BranchShareLinkTests.m, DispatchToIsolationQueueTests.m - Branch_setBranchKeyTests.m - UITestCaseMisc.m, UITestCaseTracking.m, UITestSendV2Event.m - UITestSetIdentity.m, Branch-SDK-Tests-Bridging-Header.h ## Branch-TestBed Configuration Updated Branch-TestBed Xcode project: - Configured SPM package dependency reference - Updated project.pbxproj with proper target dependencies - Removed Package.resolved to allow flexible dependency resolution - Updated all test schemes for SPM compatibility - Modified AppDelegate.m and ViewControllers for async initialization ## Project Structure Cleanup Organized source files into proper directory structure: - Created `Sources/BranchSwiftSDK/` for Swift implementation - Moved configuration files to appropriate locations - Removed duplicate/temporary Swift files from previous iterations - Updated both BranchSDK.xcodeproj and Package.swift configurations ## Key Features - Structured concurrency with proper cancellation support - Actor-based thread safety eliminating race conditions - Automatic main thread dispatching for UI callbacks - Session validation matching Android implementation - Performance optimized with cooperative thread pool - Serial request processing ensuring proper ordering - Modern async/await API for Swift developers - Full backward compatibility with existing Objective-C code
1 parent 6b2d149 commit 618e87d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1699
-525
lines changed

Branch-TestBed/Branch-SDK-Tests/BNCAPIServerTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#import "BNCSystemObserver.h"
1212
#import "BNCConfig.h"
1313
#import "BranchConstants.h"
14-
#import "Branch.h"
14+
@import BranchSDK;
1515

1616
@interface BNCAPIServerTest : XCTestCase
1717

Branch-TestBed/Branch-SDK-Tests/BNCODMTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <XCTest/XCTest.h>
10-
#import "Branch.h"
10+
@import BranchSDK;
1111
#import "BNCPreferenceHelper.h"
1212
#import "BNCRequestFactory.h"
1313
#import "BNCEncodingUtils.h"

Branch-TestBed/Branch-SDK-Tests/BNCPasteboardTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import <XCTest/XCTest.h>
1010
#import "BNCPasteboard.h"
11-
#import "Branch.h"
11+
@import BranchSDK;
1212

1313
@interface BNCPasteboardTests : XCTestCase
1414

Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <XCTest/XCTest.h>
1010
#import "BNCPreferenceHelper.h"
1111
#import "BNCEncodingUtils.h"
12-
#import "Branch.h"
12+
@import BranchSDK;
1313
#import "BNCConfig.h"
1414

1515
@interface BNCPreferenceHelper()

Branch-TestBed/Branch-SDK-Tests/Branch-SDK-Tests-Bridging-Header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// Module headers for Branch SDK unit testing.
33
//
44

5-
#import "Branch.h"
5+
@import BranchSDK;

Branch-TestBed/Branch-SDK-Tests/BranchActivityItemTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <XCTest/XCTest.h>
10-
#import "Branch.h"
10+
@import BranchSDK;
1111

1212
@interface BranchActivityItemTests: XCTestCase
1313
@end

Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <XCTest/XCTest.h>
10-
#import "Branch.h"
10+
@import BranchSDK;
1111
#import "BranchConstants.h"
1212
#import "BNCPasteboard.h"
1313
#import "BNCAppGroupsData.h"

Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import <XCTest/XCTest.h>
1010
#import "BranchLogger.h"
11-
#import "Branch.h"
11+
@import BranchSDK;
1212

1313
@interface BranchLoggerTests : XCTestCase
1414

Branch-TestBed/Branch-SDK-Tests/BranchQRCodeTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import <XCTest/XCTest.h>
10-
#import "Branch.h"
10+
@import BranchSDK;
1111
#import "BranchQRCode.h"
1212
#import "BNCQRCodeCache.h"
1313

Branch-TestBed/Branch-SDK-Tests/BranchShareLinkTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <XCTest/XCTest.h>
1010
#import "BranchShareLink.h"
1111
#import "BranchLinkProperties.h"
12-
#import "Branch.h"
12+
@import BranchSDK;
1313

1414
@interface BranchShareLinkTests : XCTestCase
1515

0 commit comments

Comments
 (0)