Crash in Swift Data on iOS 17.5, Resolved in iOS 18.0 Developer Beta

Hey everyone,

I'm a new developer working on my app. I'm facing an unusual problem during the App Store review process. The app works perfectly on my physical devices, running iOS 18.0 developer beta, but it consistently crashes on simulators with iOS 17.5. Due to this issue, my app has been rejected for iOS 17.5 because of the crashes. I know I should have avoided developing and testing the app on different versions, so please go easy on me :(

Crash Details:

Steps Leading to Crash:

  • Opened the app
  • Went to the Stocks section
  • Clicked on Buy
  • App crashed

The Breakpoint Exception:

Thread 1: EXC_BREAKPOINT (code=1, subcode=0x21b9f1620)

Generated Infrastructure Code Section Triggering Crash:

{
    @storageRestrictions(accesses: _$backingData, initializes: _stock)
    init(initialValue) {
        _$backingData.setValue(forKey: \.stock, to: initialValue)
        _stock = _SwiftDataNoType()
    }
    get {
        _$observationRegistrar.access(self, keyPath: \.stock)
        return self.getValue(forKey: \.stock)
    }
    set {
        _$observationRegistrar.withMutation(of: self, keyPath: \.stock) {
            self.setValue(forKey: \.stock, to: newValue)
        }
    }
}

The crash appears to be related to Swift Data handling during the trade operation in my app's TradeView.

While I've managed to temporarily fix the issue by running the app on iOS 18.0, this is not a practical solution for the App Store release, which is my immediate concern.

Has anyone else experienced similar issues with Swift Data on iOS 17.5? If yes, how did you solve it? Is there a known workaround or a better approach to ensure compatibility with iOS 17.5?

Thank you in advance for your valuable assistance. I truly appreciate your help!

The code you posted is generic to all Observation objects, including Models in SwiftData, so it is not going to be helpful. Your steps to reproduce are also not helping us to help you because of course we don't have your app's code.

The most likely root cause of your crash is related to the fact that Views in iOS 18 are now implicitly annotated with @MainActor. If you are running code that requires it to be on the main actor, it will work silently in iOS 18, but will fail in earlier versions of iOS.

Also, be aware that Apple will not approve any apps that use Xcode 16 until it reaches release candidate. You have to use Xcode 15 and target iOS 17 until then to be approvable.

Good luck to you

I literally have same problem right now, can you develop on how you fixed it? @MauiWowieMan

Crash in Swift Data on iOS 17.5, Resolved in iOS 18.0 Developer Beta
 
 
Q