E
E
Evgeny Konkin2017-02-14 12:58:28
Swift
Evgeny Konkin, 2017-02-14 12:58:28

Divide an array of objects into sections and count?

Hi all!
There is a ProviderClass class, about 200 objects.
a9007dbb18504aeaaf5d50ae46e7d96d.png
Please tell me how to calculate the number of lines in each section by the "grp" parameter. It’s impossible to count the number of lines in any way, the number of sections seems to have been calculated:

func numberOfSections(in tableView: UITableView) -> Int {
        return Set(providers.map{$0.grp}).count
 }

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
ManWithBear, 2017-02-14
@ManWithBear

From your object, make some structures:

struct Element {
    let id: String
    let title: String
    let isVisible: Bool
}
struct Group {
    let id: String
    let elements: [Element]
}
struct Provider {
    let groups: [Group]
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question