Loops

forEach is the preferred way of dealing with loop in a Senior life. for in is what you learn in school. Or in other words, next step of walking – running.
Do it like adults do.

// Don't
for val in sequence {
		value.doSomething(
}

// Do
sequence.forEach {
		$0.doSomething()
}

// Do
sequence.forEach { value in
		value.doSomething()
}

Of course there are times when you need for in, but more about that later on.

Leave a Comment