如何为下面给出的示例创建数据模型,以便我可以动态开发任何大小的数组? 我的数据就像
let dataArray = [[
self.keyIndent: 0, self.keyTitle: "title 0", self.keyChildren: [[
self.keyIndent: 1, self.keyTitle: "title 01", self.keyChildren: [[
self.keyIndent: 2, self.keyTitle: "title 011", self.keyChildren: [[
self.keyIndent: 3, self.keyTitle: "title 0111", self.keyChildren: [[
self.keyIndent: 4, self.keyTitle: "title 01111", self.keyChildren: []], [self.keyIndent: 4, self.keyTitle: "title 01112", self.keyChildren: []]]]]]]]]]]
答案 0 :(得分:0)
我不确定你在寻找什么,但我设计这样的模型类:
class MyModel
{
var title: String?
var children: [MyModel]?
func buildDataModel(input: [MyModel]) -> [[String:Any]]?
{
// Dynamically build your array here, by walking input and its descendents.
// keep track of the indent as you progress, so you can insert it to each dictionary as well.
}
}