2017-09-09 27 views
-2

我具有以下陣列的陣列中的迅速3如何訪問數組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)]] 

如何訪問這種類型的對象。

+2

如果你這個卡你真的需要一個斯威夫特底漆本書或引用。 [正式書](https://itunes.apple.com/us/book/the-swift-programming-language-swift-3-1/id881256329?mt=11)是免費的,值得一讀,然後再嘗試這類的thig。 – tadman

回答

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... 
    } 
} 
+0

出錯 類型'Array '的值沒有成員名稱 –

+0

@sanjayrathod,因爲Moritz指出它是數組中的一個數組,檢查如何遍歷該類型數組的更新。 –