An easy way to group your Lists in different Sections in UITableView by Date. Just download the source code from files.
- Create a Item-Class which has
GroupSections.ObjectRow
as SuperClass.
class Person: GroupSections.ObjectRow {
var id: Int
var name: String
init(id: Int, name: String) {
self.id = id
self.name = name
}
}
- Create some objects of
Person
.
var persons = [Person]()
persons.append(id: 1, name: "Mike")
persons.append(id: 2: name: "Dave")
- Change in
GroupSections
-Class the parameter fromgroup
to your custom Person-Class.
static func group(_ persons: [Person], by component: Calendar.Component) -> [Object] { ... }
- Group your objects by calling
group
.
var groupedPersons: [GroupSections.Object] = GroupSections.group(persons, by: .month)