如何访问阵列swift 3?

时间:2017-09-09 06:42:06

标签: swift

我在swift 3中有以下数组数组

[[SideMenu.medications(csMedicationID: -1, name: "test medication", startDate: "Sep 9, 2017", onGoing: true, endDate: "", type: 2, dose: "5", frequencyS: "Every 2 hours", archived: false), SideMenu.medications(csMedicationID: -1, name: "Medication 4", startDate: "Sep 9, 2017", onGoing: true, endDate: "", type: 2, dose: "5", frequencyS: "Every 2 hours", archived: false)]]

如何访问此类对象。

1 个答案:

答案 0 :(得分:1)

您有一个名为SideMenu.medications的对象,该对象是该对象的数组:[SideMenu.medications],所以这样做:

let array = [[SideMenu.medications(csMedicationID: -1, name: "test medication", startDate: "Sep 9, 2017", onGoing: true, endDate: "", type: 2, dose: "5", frequencyS: "Every 2 hours", archived: false), SideMenu.medications(csMedicationID: -1, name: "Medication 4", startDate: "Sep 9, 2017", onGoing: true, endDate: "", type: 2, dose: "5", frequencyS: "Every 2 hours", archived: false)]]

for object in array {
    for sidemenu in object {
        print(sidmenu.name)
        print(sidemenu.startDate)
        etc...
    }
}