ios – Hierarchy stage looping until array component empty in swift

0
3


Hierarchy array having -> one other Hierarchy array -> one other Hierarchy array at finish its have empty Hierarchy array

The best way to loop Hierarchy array until it attain empty component for Hierarchy.

var levelString = [String]()

func hierarchyList(){
    levelString.removeAll()
    if let hierarchLevels = self.metaData.first?.hierarchies {
        if hierarchLevels.rely > 0 {
            levelString.append(hierarchLevels.first?.title ?? "")  // Father or mother
        }
        for every in hierarchLevels {
            repeat {
                levelString.append(every.hierarchies?.first?.title ?? "") // Childs
            } whereas every.hierarchies?.rely == 0
        }
    }
}

I’ve complete 3 Components in my Hierarchy, with above code it displaying solely two component. One mother or father and for sub baby the final component is lacking.

The best way to Loop until final component and append to String array the title record.

LEAVE A REPLY

Please enter your comment!
Please enter your name here