【发布时间】:2018-08-24 16:42:15
【问题描述】:
我希望(根据此示例)在创建初始条目后将更多项目添加到结构化数组的特定部分。
struct Zoo {
let section: String
let items: [String]
}
var objects = [Zoo]()
let animals = Zoo(section: "Animals", items: ["Cat","Dog","Mouse"])
let birds = Zoo(section: "Birds", items: ["Crow","Pidgeon","Hawk"])
let reptiles = ["Snake","Lizard"]
objects.append(animals)
objects.append(birds)
// ... varous logic and proccessing where I determine I need
// to add two more items to the animals section...
// trying to extend animals with two more entries.
// this is where I am getting hung up:
objects[0].items.append(reptiles)
【问题讨论】:
-
使用 var 而不是 let stackoverflow.com/questions/24002092/…
-
将 let 更改为 vars,但在我尝试附加的最后一行得到以下表格:无法将类型“[String]”的值转换为预期的参数类型“String”
标签: arrays swift append swift4