I would say that map is not for this kind of operation. It creates a new sequence based on an others sequences elements, but what you don't want to create a sequence, you just want to iterate through them and apply a function to them. In swift there is no higher order function that matches what you want, I hope they will put something in soon. So the best you can do is to use a for loop or write your own function which does what you want.
I would like to suggest to write your own functon (based on what scalas foreach is):
extension Array {
func foreach(function: T -> ()) {
for elem in self {
function(elem)
}
}
}
UPDATED with Swift 2.0
forEach
added to the SequenceType
, so it is available:
(cell.contentView.subviews as [UIView]).forEach { $0.removeFromSuperview() }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…