0
從結構刪除記錄我有一個struct
定義爲:根據條件
struct Section {
var name: String!
var items: [String]!
init(name: String, items: [String]) {
self.name = name
self.items = items
}
}
現在怎麼可以根據記錄的項目數我篩選這個結構。說我想刪除每個記錄,如果項目是零
例如
sections = [
Section(name: "Mac", items: ["MacBook", "MacBook Air", "MacBook Pro", "iMac", "Mac Pro", "Mac mini", "Accessories", "OS X El Capitan"]),
Section(name: "iPad", items: []), // no Items in this record (remove this)
Section(name: "iPhone", items: ["iPhone 6s", "iPhone 6", "iPhone SE", "Accessories"]),
]
以上數據3記錄,其中記錄#2(的「iPad」)沒有任何項目,因此我可以從我的結構去除呢?
感謝你的幫忙,感謝你的努力。 –