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

Swift 6 Mode breaks the LaunchDarkly SDK

Open choulepoka opened this issue 1 year ago • 9 comments

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 Version build settings
  • Launch the app
  • Invoke any LD Code that takes a completion handler in parameter

Expected behavior

The call succeeds

Logs

image

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.

choulepoka avatar Dec 13 '24 23:12 choulepoka

Thank you for reporting this. We will investigate.

tanderson-ld avatar Dec 16 '24 15:12 tanderson-ld

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.

tanderson-ld avatar Dec 17 '24 21:12 tanderson-ld

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!

choulepoka avatar Jan 03 '25 18:01 choulepoka

Thank you for taking the time! When I have a moment I will check that out.

tanderson-ld avatar Jan 09 '25 21:01 tanderson-ld

@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).

kcoleman avatar Jan 21 '25 20:01 kcoleman

@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.

ld-ios-client-sdk-697dac6-Fix for xcode 16.3.patch

choulepoka avatar Apr 03 '25 01:04 choulepoka

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 ?

ThrownToys avatar Oct 09 '25 19:10 ThrownToys

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

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

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)
        }

abelonogov-ld avatar Oct 16 '25 01:10 abelonogov-ld