0

我正在尝试将 Observable Objects 与此类一起使用:-

    class malaysiaHolidays: ObservableObject
    {
        @Published var holidayName : String
        @Published var holidayDate : String
        
        init(holidayName: String, holidayDate: String)
        {
            self.holidayName = holidayName
            self.holidayDate = holidayDate
        }
        
    }

var holidayList = [malaysiaHolidays (holidayName: "Thaipusam", holidayDate: "2020-01-28"), malaysiaHolidays (holidayName: "Chinese New Year", holidayDate: "2020-02-12"), malaysiaHolidays (holidayName: "Chinese New Year", holidayDate: "2020-02-13"), malaysiaHolidays (holidayName: "Midterm School Break 1", holidayDate: "2020-03-13"), malaysiaHolidays (holidayName: "Sultan of Johor's birthday", holidayDate: "2020-03-23"), malaysiaHolidays (holidayName: "Awal Ramadan", holidayDate: "2020-04-13"), malaysiaHolidays (holidayName: "Labour Day", holidayDate: "2020-05-01"), malaysiaHolidays (holidayName: "Hari Raya Puasa", holidayDate: "2020-05-13"), malaysiaHolidays (holidayName: "Hari Raya Puasa", holidayDate: "2020-05-14"), malaysiaHolidays (holidayName: "Midyear School Break", holidayDate: "2020-05-22"), malaysiaHolidays (holidayName: "Vesak Day", holidayDate: "2020-05-26"), malaysiaHolidays (holidayName: "Agong's birthday", holidayDate: "2020-06-05"), malaysiaHolidays (holidayName: "Hari Raya Haji", holidayDate: "2020-07-20"), malaysiaHolidays (holidayName: "Midterm School Break 2", holidayDate: "2020-07-24"), malaysiaHolidays (holidayName: "National Day", holidayDate: "2020-08-31"), malaysiaHolidays (holidayName: "Awal Muharram (Maal Hijrah)", holidayDate: "2020-08-10"), malaysiaHolidays (holidayName: "Hari Malaysia", holidayDate: "2020-09-16"), malaysiaHolidays (holidayName: "Hari Hol Almarhum Sultan Iskandar", holidayDate: "2020-09-24"), malaysiaHolidays (holidayName: "Prophet Muhammad's birthday (Maulidur Rasul)", holidayDate: "2020-10-18"), malaysiaHolidays (holidayName: "Deepavali", holidayDate: "2020-11-04"), malaysiaHolidays (holidayName: "Year End School Break", holidayDate: "2020-11-20"), malaysiaHolidays (holidayName: "Christmas", holidayDate: "2020-12-25")]

问题是,我不确定如何在 ContentView 继续

struct HolidayView: View
{
    @ObservedObject var finalHolidayList : ???    // <<<- here
    @ObservedObject var finalStateTitle : TheStateTitle = TheStateTitle(stateTitle: "Johor")
    

任何人都可以帮忙吗?谢谢。

4

1 回答 1

0

malaysiaHolidays似乎是一个定义结构的结构。

struct malaysiaHoliday {
    var holidayName: String
    var holidayDate: String
}

实际ObservableObject可能是HolidayList

class HolidayList: ObserableObject {
    @Published var holidayList: [malaysiaHolidays] = []
    ...
}

在您看来:

struct HolidayView: View
{
    @ObservedObject var holidayList: HolidayList = ... <- you can init here

    ...
}
于 2020-11-26T05:47:52.830 回答