Commit 618e87d
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 code1 parent 6b2d149 commit 618e87d
File tree
43 files changed
+1699
-525
lines changed- Branch-TestBed
- Branch-SDK-Tests
- Branch-SDK-Unhosted-Tests
- Branch-TestBed-UITests
- Branch-TestBed.xcodeproj
- Branch-TestBed
- BranchSDK.xcodeproj
- Sources
- BranchSDK
- Public
- BranchSwiftSDK
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| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
0 commit comments