2017-09-09 29 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指出它是数组中的一个数组,检查如何遍历该类型数组的更新。 –