Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively loop through array of arrays using functional

Tags:

ios

swift

I want to loop through my view subviews, and for each subview loop through its subviews and etc.

so let say I have the following code:

let view = myVC.view
view.backgroundColor = UIColor.clearColor()

then repeat this same for each subview. I want to do it functionally.

any insight is much appreciated.

EDIT:

to make it clear

I'm looking for something like this:

view.subviews.chanageColor() { (aView, aColor) in
aView.backgroundColor = aColor
}

but it should be recursive it goes to each view subview.

like image 251
Omar Al-Shammary Avatar asked Mar 14 '23 05:03

Omar Al-Shammary


1 Answers

Something like this?

func makeAllSubviewsClear(view: UIView!)
{
    view.backgroundColor = UIColor.clearColor()
    for eachSubview in view.subviews
    {
        makeAllSubviewsClear(eachSubview)
    }
}

called via:

let view = myVC.view
makeAllSubviewsClear(view)
like image 134
Michael Dautermann Avatar answered Mar 16 '23 16:03

Michael Dautermann