Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Xcode warns that onChange(of:perform:) is deprecated in iOS 17

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

Short answer

onChange(of:perform:) is deprecated since iOS 17, macOS 14, watchOS 10. Replace it with onChange(of:initial:_:). Use the zero-parameter closure when you read the state yourself, or the two-parameter closure when you need the old and new value. Add initial: true only if the action must also run when the view appears.

  • Applies to Xcode 26, SwiftUI iOS 17, iOS 18, iOS 26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List every call site of the old form so you can change them one by one.

    grep -rn "onChange(of:" --include=*.swift .
  2. 2Match what you see, then jump to its fix

    1. 1The old closure ignores its parameter, or reads the same value from your own stateThe closure only needs to know that the value changedFix
    2. 2The old closure is { newValue in ... } and you compare against a stored previous valueThe closure uses the new value, and you now also want the old oneFix
    3. 3The same logic was duplicated in .onAppear and in the old onChangeThe action must also run when the view first appearsFix

What does the error look like?

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

Cause 1 of 3

The closure only needs to know that the value changed

1Check

Open the call. If the closure body never uses the new value that onChange passed in, the zero-parameter form fits.

grep -rn -A2 "onChange(of:" --include=*.swift Sources/

2Fix

Drop the closure parameter. The modifier is the same call without perform:, and the closure takes no arguments.

// before
.onChange(of: playState) { newState in
    model.playStateDidChange(state: newState)
}

// after
.onChange(of: playState) {
    model.playStateDidChange(state: playState)
}

3Verify

Build. The deprecation warning for that call disappears.

# Xcode: Product > Build (Cmd+B)

Confirmed by developer.apple.com

Did this fix it?

Cause 2 of 3

The closure uses the new value, and you now also want the old one

1Check

The two-parameter closure receives the old value first and the new value second, so a manually stored previous value is not needed.

grep -rn "onChange(of:.*in" --include=*.swift .

2Fix

Use the two-parameter closure and name both arguments.

.onChange(of: scenePhase) { oldPhase, newPhase in
    if newPhase == .background {
        cache.empty()
    }
}

3Verify

Build, then move the app to the background and check the cache is emptied.

# Xcode: Product > Build (Cmd+B)

Confirmed by developer.apple.com

Did this fix it?

Cause 3 of 3

The action must also run when the view first appears

1Check

By default the new modifier runs the action only on later changes. The initial parameter controls whether it also runs when the view initially appears. It defaults to false.

grep -rn -B1 -A3 "onAppear" --include=*.swift .

2Fix

Pass initial: true and remove the duplicate .onAppear call.

.onChange(of: selection, initial: true) {
    loadDetails(for: selection)
}

3Verify

Open the screen. The details load once on appear and again when selection changes.

# Xcode: Product > Build (Cmd+B)

Confirmed by developer.apple.com

Did this fix it?

How do I stop it coming back?

  • Use the zero-parameter form by default and reach for old and new values only when the logic compares them.
  • Treat new deprecation warnings as build issues in CI so they are fixed while the call sites are few.
  • Keep long work out of the action closure. Apple notes the system may call it on the main actor, so detach a background task for slow work.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Mobile apps

App record creation fails because you lack permission

You cannot add a new app in App Store Connect as a Developer or limited user

Only the Account Holder, an Admin or an App Manager can create an app record, and Apple blocks it until the Account Holder has signed the latest agreement.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.