Thursday, May 16, 2024
HomeiOS Developmentios - Points including new objects to mannequin's string array and displaying...

ios – Points including new objects 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 means.

@Mannequin
closing 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 {
            return
        }

        var updatedReports = stashed.userReports ?? []

        updatedReports.append(inputReport)

        attempt? modelContext.save()

        dismiss()
    }
}

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

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

   // unsure im im doing this block  accurately

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



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments