App freezes when built with Xcode 16 on iOS 18, but not on iOS 17 or lower, or with Xcode 15 on iOS 18

I'm experiencing an issue where my app freezes when built with Xcode 16 on iOS 18.

Additional Information:

  • The issue does not occur when building the app with Xcode 16 on iOS 17 or lower.
  • The issue does not occur when building the app with Xcode 15 on iOS 18.
  • The CPU usage spikes to 100% when the app freezes.
  • The app specifically freezes after the code runs into .sink(receiveValue:).

Here is the relevant code snippet:

    @Published var selectedCardData: CardData?
    @Published var selectedRootTab: RootViewTab = .statement

    override func load() {
        state = .loading
            
        $selectedCardData.ignoreNil()
            .removeDuplicates()
            .map { [unowned self] cardData in
                $selectedRootTab.filter { $0 == .statement }
                    .first()
                    .map { _ in cardData }
            }
            .switchToLatest()
            .sink(receiveValue: { value in
                print(value) // value not nil
                print("Execution reaches this point and the app freezes (CPU 100%).")
            })
            .store(in: &cancellables)
    }

Are there any known changes in iOS 18 or Xcode 16 that might affect this code?

Answered by Baldman68 in 805469022

We are having a similar issue. We tracked it down to when we are updating @Published vars in our view models, but have not found a work around. We are not having the app freeze, but see the CPU spiking over 100% then staying pegged at 100% until we close the app.

If we run the app on a device that's at ios 17.6, no issues. Only when we run on an iOS 18 device do we see the problem.

Accepted Answer

We are having a similar issue. We tracked it down to when we are updating @Published vars in our view models, but have not found a work around. We are not having the app freeze, but see the CPU spiking over 100% then staying pegged at 100% until we close the app.

If we run the app on a device that's at ios 17.6, no issues. Only when we run on an iOS 18 device do we see the problem.

Same issue( I’m using custom TabBar. After changing tab, in a second the CPU usage raises to 100% and app freezes. Issue appeared when i‘ve updated xcode to 16 version. Still haven't found a solution

App freezes when built with Xcode 16 on iOS 18, but not on iOS 17 or lower, or with Xcode 15 on iOS 18
 
 
Q