TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Help with onChange

Forums > SwiftUI

@Genka  

Good afternoon, don't judge me harshly, but I'm a novice developer trying to figure it out. With the arrival of ios 17, onChang needs to be written in a new way, and now I don't understand how it needs to be redone. Here is my old code and I don't understand how it needs to be redone

  var body: some View {
        content (separateTasks().0, separateTasks().1)
            .onChange(of: filterDate) { newValue in
                //очистка старого предиката
                result.nsPredicate = nil

                let calendar = Calendar.current
                let startOfDay = calendar.startOfDay(for: newValue)
                let endOfDay = calendar.date(bySettingHour: 23, minute: 59, second: 59, of: startOfDay)!
               let predicate = NSPredicate(format: "date >= %@ AND date <= %@", argumentArray: [startOfDay, endOfDay])

                /// Назначение нового предиката
                result.nsPredicate = predicate
            }
    }

2      

onChange has now either none or two parameters. Change

.onChange(of: filterDate) { newValue in

to

.onChange(of: filterDate) { oldValue, newValue in or .onChange(of: filterDate) { _, newValue in

3      

@Genka  

thank you very much

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.