Reputation: 3655
I am apptemting to learn SwiftUI, Swift, and Xcode for macOS. The code below works but I'd like to have no warnings. The complete warning is:
'onChange(of:perform:)' was deprecated in macOS 14.0: Use
onChange
with a two or zero parameter action closure instead.
but I cannot interpret it. I'm using macOS 15
This works but the warning is generated.
.onChange(of: thisImageIndex) { newValue in
// Update currentDatum when the index changes
if newValue >= 0 && newValue < imageList.count {
currentDatum = imageList[newValue]
imageCaption = currentDatum!.displayName
}
}
Upvotes: 4
Views: 1755
Reputation: 2641
To remove warning, you need to update your code to add old value
.onChange(of: thisImageIndex) { oldValue, newValue in
// Update currentDatum when the index changes
if newValue >= 0 && newValue < imageList.count {
currentDatum = imageList[newValue]
imageCaption = currentDatum!.displayName
}
}
Upvotes: 3
Reputation: 3655
I figured it out for my purpose! I guess I'm getting better at this!
.onChange(of: thisImageIndex) { if thisImageIndex >= 0 && thisImageIndex < imageList.count { currentDatum = imageList[thisImageIndex] imageCaption = currentDatum!.displayName } }
Upvotes: 0