|
Hi guys, I have no idea how to implement a save functionality to the app. Is it better to use JSON or Core Data in my case? Regarding the code I wrote, is it good or does it need improvement? Could you do a code review and give me some ideas for saving? Thank you
|
|
Hi @andreasara-dev, There are a few things i noticed,
as for saving i personally went with JSON i think Core Data is kind of an over kill, i use an extension on
so i would just call the encode and decode
|
|
Ok I resolved the bugs, but I can't figure it out where to call the functions for decode and encode. I need to create an enum CodingKey to add Codable conformance to the class? How can I tackle this? Thank you guys |
|
Hi, Yes, you need three things,
and that will add Codable conformance to the class.
after that you would call your decode and encode functions,
for example you could call the decode function from the original init (Not the required one ) so it populates the variables
and you could call the encode in your check out this article on cupcake corner to see how you would add conformance to the class. Adding Codable conformance for @Published properties |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and more!
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.