为创建部分创建模型 - Swift

Create a model for create section - Swift

我需要创建一个带有部分的 UITableView,我的值如下所示:

let sectionTitles = ["section-1", "section-2", "section-3"]

let Items = [["id": 100, "name":"jim", "family": "rason"],["id": 200, "name":"jim22", "family": "rason22"], ["id": 300, "name":"jim33", "family": "rason33"]]

并且:

section-1 用于 ["id": 100, "name":"jim", "family": "rason"]

section-2 用于 ["id": 200, "name":"jim22", "family": "rason22"]

section-3 用于 ["id": 300, "name":"jim33", "family": "rason33"]

如何为其创建模型并填充该模型?

有创建模型的在线网站吗?

你需要

struct Section {
   let title:String
   let content:[Content]
}

struct Content {
   let id:Int
   let name,family:String
}

然后创建数组

let arr = [Section(title:"First",content:[Content(id:100,name:"na",family:"fam")])]

您可以使用 Class 或这样的结构创建模型

struct Section {
    let title:String
    let content:SectionData
}

struct SectionData {
    let id:Int
    let name,family:String
}

创建数组

var arr : [Section] = []

并在数组中追加数据

arr.append(Section(title:”Section1”, content: Content(id: 1, name: "lokesh", family: "hdf")))
 arr.append(Section(title:"Section2”, content: Content(id: 1, name: "lokesh", family: "hdf")))
   arr.append(Section(title:"Section3”, content: Content(id: 1, name: "lokesh", family: "hdf")))