|
Hi there, I have a datePicker and a TextEditor in a VStack. Now I want to be able to select a date, then edit and save text for this date. By chosing another date there should be a placeholder-text (if there hasn't been an entry yet) or the text I wrote sometime before. What is the best way to do that? Can I store the On the long run, I want to store it permanantly, so I think I'll have to use CoreDate for it(?). But for now I would like to learn the connection between the datePicker and the TextEditor. Or is CoreData the way to go in the first place? Thank you. Stam (on Xcode 12.5.1) |
|
Why you need TextEditor to edit dates, you can formate dates by using dateFormatter. In dateFormatter computed property you can edit it.
|
|
Thank you for the dateFormatter, this will come in handy later I think. I do not want to edit dates, I want to save a note with the date of that day. By changing the date via the DatePicker, I want the note in TextEditor change to the note for this day, so I can reread and edit my notes.
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
Ok you can save the date to coreDate directly by this way, you don't have to do this in TextField:
which viewContext is your corData context. You have to create date attribute in your Note Entity with type Date |
|
Rather than having the
Or:
Also note that you don't need to use both |
|
So, you are basically saying, CoreData is the way to go? Implemented saving which seems to work as wanted. Next step is fetching and filtering all the notes to only show the ones specific for the day. And listing them in the TextEditor. Great, lets try. Any tips? |
|
I think you want somthing like this, try this code:
|
|
well, I couldn't try it, because of some errors I couldn't resolve. AppDelegate wasn't found, this seems to cause other context-errors. But my setup is pretty similar, I think. I haven't made a viewModel yet, instead I have an @Environment-Object. Saving, fetching and presenting the notes in the List works. How do I filter them, so only notes of the selected date are shown? I haven't figured out the correct predicate-format.
|
|
|
|
Great! This works for me, too. Of cause there will pop up a lot of other difficulties and questions going on from here, but I think thats all for this topic. Thank you for helping me out. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates.
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.