fix: Fix crash calling API with non-main thread completions from Swift6 #454
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Requirements
I have added test coverage for new or changed functionality
Tests can not be added, package doesn't compiles under Swift6
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
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 LaunchDarklyif you want to turn related compiler errors into warningsProof 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.
@Sendableon public callbacks inLDClient.swift:setOnline(_:completion:)identify(context:completion:)(deprecated) and allidentifyoverloads (includinguseCache:andtimeout:variants)start(config:context:completion:)andstart(... startWaitSeconds: ... completion:)LDClient.swift(observe,observe(keys:),observeAll,observeFlagsUnchanged,observeCurrentConnectionMode).@preconcurrency import LaunchDarklyto mitigate compilation issues.Written by Cursor Bugbot for commit 1c5c111. This will update automatically on new commits. Configure here.