假设我有一组要在每个 UITouch 上运行的闭包。 这是我使用的代码:
touches.filter { touch in
return touch.phase == .Ended && touch.tapCount == 1
}.forEach { touch in
actionsOnTap.forEach { action in
action(touch)
}
}
令我烦恼的是嵌套的 forEach 语句,我想有一些简洁的方法可以完全适用于这种情况,但我想不出。谁能给我一个提示?
最佳答案
就个人而言,我喜欢嵌套。我会写:
for touch in touches {
if touch.phase == .Ended {
if touch.tapCount == 1 {
actionsOnTap.forEach {$0(touch)}
}
}
}
对我来说,这很干净而且(最重要的)清晰。
关于ios - Swift - 避免嵌套的 forEach 闭包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37444786/