Xcode warns that onChange(of:perform:) is deprecated in iOS 17
'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.
Fix it fast
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 .2Match what you see, then jump to its fix
- 1
The old closure ignores its parameter, or reads the same value from your own stateThe closure only needs to know that the value changedFix - 2
The 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
The same logic was duplicated in .onAppear and in the old onChangeThe action must also run when the view first appearsFix
- 1
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
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
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
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
Cannot change the App Privacy answers in App Store Connect
Publish Your App Privacy Responses?
Only the Account Holder, Admin and App Manager roles can answer the App Privacy questions.
2 causes, each with a fixMobile 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 fixMobile apps
You cannot find the button to pull your app back from review
No 'remove this version from review' message appears on the version page
There is no button called Reject Binary.
3 causes, each with a fixMobile apps
Your Apple Account cannot sign in to App Store Connect
Sign-in to App Store Connect is refused for an account that should have access
App Store Connect does not open to every Apple Account.
3 causes, each with a fixMobile apps
Apple rejected the app under Guideline 4.3, Design: Spam
Guideline 4.3(b) - Design - Spam
Guideline 4.3 is Apple's duplicate rule.
5 causes, each with a fixMobile apps
App Store Connect rejects a screenshot because it has transparency
Images can't include alpha channels or transparencies.
App Store Connect does not accept screenshots that carry an alpha channel or transparent pixels.
2 causes, each with a fix