|
How to modify data in corredata from a view, some one can help me understaning the logic? I have recreate a view with the form and i would like to put the data in the form automatcly, so people could change it and i would like to save again. But I ahve problem to pass the data in the form fild For example I create @State var titolo = "" TextField("Task Name", text: $titolo) How can I pass to the text field the record? Thanks |
|
In order to provide you with proper logic it's advisable that you provide more information about the structure of the workflow in your views. If you want to use core data entity you probably sent fetch request to core data, and you recevied fetch request results, and somehow placed it on your view, then probalby you tap an item and at this particular moment you can pass item to view where you can display that info in the TextField and modify it. You cannot throw a bunch of items in your TextField, without choosing an item you want to work with. Then when you have single item to work with you can modify and save edited item in moc or managed object context. But this is only my guesses :) For sure there are many other ways to do that, but without knowing how you structured your workflow it is rather difficult to say. Possible code might look something like this
|
|
I try to insert ho add .onAppear { titolo = diario?.titolo ?? "" }
/Users/davide/Documents/swiftui100day/Diario-emotivo/Diario-emotivo/ModifyDiarioView.swift:83:42: error build: Cannot use optional chaining on non-optional value of type 'Diario' Thanks for your help |
|
|
|
As @Bnerd correclty indicated, you have to remove ? aka optional chaining. In my example i passed the item which is optional |
|
Thank you very much for the help you have given me, I am truly grateful. You saved me a lot of time. As much as I try to follow the tutorials this part is still quite difficult for me. Good evening |
|
Always welcome! We all gone through this, it takes some time to absorb CoreData mistery. Still a lot to learn even for myself :) |
SPONSORED Transform your career with the iOS Lead Essentials. This Black Friday, unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a free crash course.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.