EDIT: (thanks Jeremiah / Rollo)
By far the best way to do this in Swift for iOS is:
view.subviews.forEach({ $0.removeFromSuperview() }) // this gets things done
view.subviews.map({ $0.removeFromSuperview() }) // this returns modified array
^^ These features are fun!
let funTimes = ["Awesome","Crazy","WTF"]
extension String {
func readIt() {
print(self)
}
}
funTimes.forEach({ $0.readIt() })
//// END EDIT
Just do this:
for view in self.view.subviews {
view.removeFromSuperview()
}
Or if you are looking for a specific class
for view:CustomViewClass! in self.view.subviews {
if view.isKindOfClass(CustomViewClass) {
view.doClassThing()
}
}