fix: Fix crash calling API with non-main thread completions from Swift6
Requirements
-
[x] I have added test coverage for new or changed functionality Tests can not be added, package doesn't compiles under Swift6
-
[x] I have followed the repository's pull request submission guidelines
-
[x ] I have validated my changes against all supported platform versions Test on different XCode versions using both Swift5 and Swift6
Describe the solution you've provided
Fixes crash of using not main-thread completions called from Swift6 application
- Annotates all non-main closures in the public method as @Sendable. It removes crash, but might add compiler warning or compilation error if body of closure uses UI code.
Describe alternatives you've considered
Run all completions on the main thread. Didn't make because it would change existing behavior, which might be provided in big version update.
Additional context
use @preconcurrency import LaunchDarkly if you want to turn related compiler errors into warnings
Proof of testing
[!NOTE] Annotates public completion/handler closures with @Sendable for Swift 6 compatibility and updates docs (main-thread notes) plus README guidance to use @preconcurrency import.
- API/Concurrency:
- Mark
@Sendableon public callbacks inLDClient.swift:
setOnline(_:completion:)identify(context:completion:)(deprecated) and allidentifyoverloads (includinguseCache:andtimeout:variants)start(config:context:completion:)andstart(... startWaitSeconds: ... completion:)- Docs:
- Clarify parameter docs that observe handlers execute on the main thread in
LDClient.swift(observe,observe(keys:),observeAll,observeFlagsUnchanged,observeCurrentConnectionMode).- README:
- Add Swift 6 note to use
@preconcurrency import LaunchDarklyto mitigate compilation issues.Written by Cursor Bugbot for commit 1c5c1110c23f76173e3d25a678c74bbd1eaf434d. This will update automatically on new commits. Configure here.
I've given this a go, and it seems to have fixed the crash I was seeing. Thanks for moving on this - LGTM