Changing minimum deployment to iOS 17.0 Xcode compiler issues

I am developing an app that's near release. I changed the minimum deployment from iOS 16.X to 17.0 in order to be able to use the TipKit Framework.

Making that change generated a ton of compiler warnings:

.onChange(of:perform:)' was deprecated in iOS 17.0: Use onChange with a two or zero parameter action closure instead.

After I fixed dozens of the warnings without issue, each subsequent attempt to fix a warning generated a compiler error:

The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions.

I decided to focus on just one file that had 13 different .onChange invocations. Nine were successfully converted to the new call, four were still deprecated. I tried to trace any possible source of type-check error for some of the simplest .onChange cases but nothing other than commenting out the .onChange in its entirety "fixed" the error.

I tried commenting out one of the fixed/converted .onChange calls first and then fixing one of the problematic ones and that worked, no type-check error. The bottom line seems to be that I can only have nine of the new .onChange calls in that file, the other four have to be in the deprecated format or commented out.

I tried upping the minimum deployment from 17.0 to 17.5 and that didn't work. I tried using a clean build folder and that also didn't work.

Right now, I'm running Xcode 15.4 on Sonoma 14.7.2. I'm trying to avoid updating to the latest Xcode to avoid adding confounding variables and/or other possible issues. I am aware that for submission and release I will have to do so, I want to do it "on my terms" when everything is working properly.

Any help would be appreciated.

Answered by AndrewH in 829789022

It appears that the limitation is at the view builder/container level. Adding another ZStack at the top level and splitting the .onChange calls fixes/addresses the error. Thank you to my son who suggested the fix.

var body: some View {
        ZStack {
            ZStack {
             // View code 
            }
            .onChange() // 1
             ...
            .onChange() // 9
        }
       .onChange() // 10
             ...
       .onChange() // 14
}

We can't really do anything without seeing any code.

Generally, I've gotten those warnings if I've done something wrong, but it's not obvious what.

Can you post what you changed the onChange from and to?

@darkpaw The point I tried to make was there appears to be a functional limit now as to how many .onChange calls you can have in a file that did not exist with the deprecated call.

I can make ANY 9 of 13 updated .onChange calls work, just not all 13 at once.

The code changes themselves are trivially simple:

iOS 16:

.onChange(of: modeSelection) { newValue in
      workout.modeSelection = newValue
       settingsModified = true
 }

iOS 17:

.onChange(of: modeSelection) {
      workout.modeSelection = modeSelection
      settingsModified = true
  }
Accepted Answer

It appears that the limitation is at the view builder/container level. Adding another ZStack at the top level and splitting the .onChange calls fixes/addresses the error. Thank you to my son who suggested the fix.

var body: some View {
        ZStack {
            ZStack {
             // View code 
            }
            .onChange() // 1
             ...
            .onChange() // 9
        }
       .onChange() // 10
             ...
       .onChange() // 14
}
Changing minimum deployment to iOS 17.0 Xcode compiler issues
 
 
Q