Swift 6 Mode breaks the LaunchDarkly SDK
Describe the bug
When enabling Swift 6 and invoking LDClient.identify(context:timeout:completion:), the program will hard crash.
To reproduce
- Enable Swift 6 on your project using the
Swift Language Versionbuild settings - Launch the app
- Invoke any LD Code that takes a completion handler in parameter
Expected behavior
The call succeeds
Logs
Library version
9.12.0
XCode and Swift version
Code 16.2, Swift 6, iOS Simulator 18.2
Platform the issue occurs on
iPhone, iPad & Mac Catalyst
Additional context
For the LDClient.start(config:context::startWaitSeconds:completion:), the completion is nillable, so by specifying nil, this call does not crash. But if you add a completion handler, it will hard crash.
Thank you for reporting this. We will investigate.
Hi @choulepoka, I have been unable to reproduce this issue. I tried with XCode 16.2, Swift 6, and a simulator running 18.2. I also tried with various combinations of actors to see if that was involved, but no luck there either. I don't doubt what you're seeing is an issue, just need additional help getting it to happen.
Would you be willing to make a minimal reproducible project? Getting it to happen in our hello-ios-swift may be an option.
Hi @tanderson-ld ! Sorry for the delay. I have created a fork of the hello-ios-swift project and adjusted it to reproduce the bug
https://github.com/choulepoka/hello-ios-swift
The issue seems to occurs when I set the minimum iOS version to 15 (up from the project's original iOS 12)
Cheers!
Thank you for taking the time! When I have a moment I will check that out.
@tanderson-ld Hello, I am experiencing a crash in this same method, only when running under Swift 6. I have determined it occurs for me only when the config.startOnline is set to the default of true. If I set it to false, it does not crash. When the startOnline value is true, It crashes on line 841 with a EXC_BREAKPOINT. Running on iOS, version 9.12.2. It does not crash when the completion is nil. Also, the initial call I make is to the LDClient class start method that appears on line 821, which then calls the start method on line 829 (which is the method where the actual crash occurs on line 841).
@tanderson-ld I have forked the iOS SDK Repository, and made a few minor improvements, making it compile with xcode 16.3, and compatible with the Swift 6 mode.
Here is the patch if you are interested.
Appreciate your work here @choulepoka . This is still an issue in 9.15.0 and Xcode 26. Any plans to incorporate this fix in a versioned release soon @tanderson-ld ?
Hi @choulepoka
I created backward compatible fix of Swift6 crashes when non-main threaded completion is used in LDClient.
https://github.com/launchdarkly/ios-client-sdk/pull/454
Hi @choulepoka, @ThrownToys, @tanderson-ld
There is also workaround, you need wrap call into function with @Sendable completion.
func startFromSwift6(completion: (@Sendable(_ timedOut: Bool) -> Void)? = nil) {
LDClient.start(config: config, context: context, startWaitSeconds: 30, completion: completion)
}
startFromSwift6() { timedOut in
print(timedOut)
}