Textfield data editing and change detection

Hi all,

I am trying to detect when a textfield has changed to run code only in that chase however I am trying to edit existing data so I have to preload the textfield on appear of the editing page and this triggers the .onChange. I have tried to set the variable to false after the data is loaded but it didn’t help. Any help will be appreciated. Thanks

TextField("\(labResults.nickel)", text: $nickelLabResult)
                            .textFieldStyle(.roundedBorder)
                            .keyboardType(.decimalPad)
                            .frame(width: textfieldWidth)
                            .onChange(of: nickelLabResult) {
                                nickelChanged = true
                            }
.onAppear{
                
                if isEditMode {
                    nickelLabResult = String(labResults.nickel)
                }
                nickelChanged = false
            }

I have managed to sort this out. If everyone is interested here is the code.

TextField("Nickel", text: $nickelLabResult)
                            .textFieldStyle(.roundedBorder)
                            .keyboardType(.decimalPad)
                            .frame(width: textfieldWidth)
                            .onChange(of: nickelLabResult, { oldValue, newValue in
                                if labResults.nickel == Double(newValue) {
                                    nickelChanged = false
                                } else if Double(oldValue) != Double(newValue) {
                                    nickelChanged = true
                                }
                            })
.onAppear{
                
                if isEditMode {
                    nickelLabResult = String(labResults.nickel)
                }
            }