Type casting in for-in loop

后端 未结 6 1656

I have this for-in loop:

for button in view.subviews {
}

Now I want button to be cast into a custom class so I can use its properties.

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 20:22

    You can also use a where clause

    for button in view.subviews where button is UIButton {
        ...
    }
    

提交回复
热议问题