0

I need to create a UITableView with section, and I have values like bellow:

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"]]

And:

section-1 is for ["id": 100, "name":"jim", "family": "rason"]

section-2 is for ["id": 200, "name":"jim22", "family": "rason22"]

section-3 is for ["id": 300, "name":"jim33", "family": "rason33"]

How can I create a model for it and I fill this model?

Is any online web site for create model?

jo jo
  • 1,758
  • 3
  • 20
  • 34

2 Answers2

2

You need

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

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

Then create the array

let arr = [Section(title:"First",content:[Content(id:100,name:"na",family:"fam")])]
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

You can create Model using Class or structure like this

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

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

Create array

var arr : [Section] = []

And Append Data in Array

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")))
Lokesh gupta
  • 94
  • 10