Save List data to device (another expansion)

Lunch Card is almost finished, though there's one major part that will need to be addressed for it to go out of development.

As from last threads, I've implemented the Cards system, made it so you can change colors, include multiple cards, and the cards stay...until you quit the app. Restarting the app (dismissing it in App Switcher and opening it back up) doesn't save all your cards. That would be a major inconvenience, as it'd be more like an App Clip than an actual App.

I've considered Core Data, writing to a text file, etc., but (1) I can't decide which one would be more convenient and (2) I don't know how I would implement it (ex. CoreData would be hard to implement especially after almost finishing it without).

Please tell me if I need to provide more code than I have in previous threads. Here they are from most recent to earliest:
  1. Force color scheme at the press of a button

  2. Variable overriding itself when adding to a list

  3. I have a function in one view, but a button that should call it in another

  4. How to pass data from a TextField to a List (SwiftUI)

The original How to pass data... post code is pretty outdated, so I would refer to the more recent threads.

Homestretch...!

Note: CardsInfo.swift and SheetInfo.swift merged to make Info.swift:
Code Block
//
//  Info.swift
//  Lunch Card (iOS)
//
//  Created by Joshua Srery on 12/21/20.
//  Additional code by OOPer on Apple Developer Forums
//
import Foundation
struct CardInfo: Identifiable {
    var name: String = ""
    var id: String = ""
    var cname: String = ""
    var code: String = ""
}
class CardsInfo: ObservableObject {
    @Published var newCard: CardInfo = CardInfo()
    @Published var cards: [CardInfo] = []
    
    func add() {
        cards.append(newCard)
    }
}
class SheetInfo: ObservableObject {
    @Published var showSheetView = false
}

Accepted Reply

I realize that this is the same situation I dealt with in my original post...I’ll start a new thread

Edit: New thread

Replies

If you do not need Core Data features and want to save the whole list at once, you should better consider using Coding.

With making CardInfo conform to Codable, you can easily convert whole Array of CardInfo into Data.
And Data can be easily writable to a file.

If you find some difficulty about this, please tell us what you think is difficult.

...you should better consider using Coding.

With making CardInfo conform to Codable, you can easily convert whole Array of CardInfo into Data.
And Data can be easily writable to a file.

Where should I start with this? Or should I just Google something like "convert whole array to data codable?"

should I just Google something like "convert whole array to data codable?

That will give you more than enough info. You just need to choose the best one for you.
Good to know. Thank you!
I found a Hacking with Swift page (hackingwithswift.com/example-code/language/how-to-convert-json-into-swift-objects-using-codable) showing how to convert JSON into Swift objects. It's pretty straightforward, though, I need to figure out how to convert cardsInfo to JSON, if at all, and if that's what I need to convert.

I need to figure out how to convert cardsInfo to JSON, if at all, and if that's what I need to convert.

Seems you know what you need. I do not know much about the Hacking with Swift pages, but in usual tips or tutorial sites, there are some links to related articles including the reverse conversion. Can't you find one?
Not on there. This is what it's suggesting:

Similar solutions…

How to handle unknown properties and methods using @dynamicMemberLookup
How to create a project using Swift Package Manager
How to fix “argument of #selector refers to instance method that is not exposed to Objective-C”
How to install a beta version of Swift
How to subclass UIApplication using UIApplicationMain

I don't think that any of these correlate with my JSON problem, but please correct me if I'm wrong.
I realize that this is the same situation I dealt with in my original post...I’ll start a new thread

Edit: New thread

Not on there. This is what it's suggesting:

Sorry, I spent some time on that site and you are right, that site lacks the exact reverse situation you found.

And with the suggested search words, I could not reach the right solution checking the first page of the result.
I though this sort of well-known solution would be found easily without practicing myself, apologies.

I will write a reply on your new thread with my code sample.