我要做的是在创建实例时根据给定的参数创建不同数据类型的数组。
例如,通过调用$sql1 = "SELECT username, date_of_birth, TIMESTAMPDIFF(YEAR, date_of_birth, CURDATE()) AS age FROM user WHERE NOT username = '$username' AND gender = '$gender1' AND (TIMESTAMPDIFF(YEAR, date_of_birth, CURDATE()) BETWEEN '$age_from' AND '$to_age')";
,我想创建一个Expense类型的数组。
另外,通过调用Section(name: "Items", SectionArrays: [Expense])
,我想创建一个Category类型的数组
Section(name: "Items", sectionArrays: [Category])
答案 0 :(得分:0)
您可以通过提供实际的数组而不只是数组类型来实现此目的。
例如,您可以将其提供给成员预初始化或为空。
var sections = [
Section(name: "Items", sectionArrays: [Expense(category: "Food", description: "Peanut butter", amount: 4.99)]),
Section(name: "Category Totals", sectionArrays: [CategoryTotal]()),
Section(name: "Overall", sectionArrays: [CategoryTotal]())
]