16 C
Tuesday, May 14, 2024

ios – Points including new gadgets to mannequin’s string array and displaying them

I’ve a property in a mannequin that Is initially empty as string array (userReports) that may maintain the customers’ notes. However after I try to append values to it and show it, it nothing updates. Racking my mind understanding knowledge persistence total so im unsure if im going about this the correct approach.

remaining class ActiveStash {
    var substanceClass: String
    var substance: String
    var weight: UInt
    var substanceCost: UInt?
    var StashDescription: String?
    var date: Date
    var unit: String
    var dosages: Int?
    var userReports: [String]?

    init(substanceClass: String, substance: String, weight: UInt, substanceCost: UInt? = nil, StashDescription: String? = nil, date: Date, unit: String, dosages: Int? = nil, userReports: [String]? = nil) {
        self.substanceClass = substanceClass
        self.substance = substance
        self.weight = weight
        self.substanceCost = substanceCost
        self.StashDescription = StashDescription
        self.date = date
        self.unit = unit
        self.dosages = dosages
        self.userReports = userReports

Perform so as to add the customers’ report back to the mannequin

    func addReport() {
        guard !inputReport.isEmpty else {

        var updatedReports = stashed.userReports ?? []


        strive? modelContext.save()


How I am trying to show the textual content after the perform name from one other web page

struct StashLinkView: View {
    @Surroundings(.modelContext) var modelContext
    let stashed: ActiveStash
    @State non-public var viewSelect = "Utilization"
    var viewName = ["Usage", "Report"]
    let currencySymbol = Locale.present.currencySymbol ?? ""
    @State non-public var isSheetShown = false
    var physique: some View {
        VStack {
           /// different code

   // unsure im im doing this block  appropriately

        VStack {
            if let userReports = stashed.userReports, !userReports.isEmpty {
                ForEach(userReports, id: .self) { report in
                    VStack {
                        Textual content(report) 
            } else {
                Textual content("No Notes")

Latest news
Related news


Please enter your comment!
Please enter your name here