ios-client-sdk icon indicating copy to clipboard operation
ios-client-sdk copied to clipboard

fix: Fix crash calling API with non-main thread completions from Swift6

Open abelonogov-ld opened this issue 4 months ago • 1 comments

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 image


[!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 @Sendable on public callbacks in LDClient.swift:
      • setOnline(_:completion:)
      • identify(context:completion:) (deprecated) and all identify overloads (including useCache: and timeout: variants)
      • start(config:context:completion:) and start(... 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 LaunchDarkly to mitigate compilation issues.

Written by Cursor Bugbot for commit 1c5c1110c23f76173e3d25a678c74bbd1eaf434d. This will update automatically on new commits. Configure here.

abelonogov-ld avatar Oct 14 '25 23:10 abelonogov-ld

I've given this a go, and it seems to have fixed the crash I was seeing. Thanks for moving on this - LGTM

ThrownToys avatar Oct 16 '25 00:10 ThrownToys