【发布时间】:2017-06-05 21:12:52
【问题描述】:
我正在寻找一种优雅的方式来遍历一个数组并将它的每个值分配给五个UILabels中的一个或多个UILabels
这段代码说明了我想要做什么(虽然它很长而且重复)
if touches.count >= 1 {
positionTouch1LBL.text = String(describing: touches[0].location(in: view))
} else {
positionTouch1LBL.text = "0.0 / 0.0"
}
if touches.count >= 2 {
positionTouch2LBL.text = String(describing: touches[1].location(in: view))
} else {
positionTouch2LBL.text = "0.0 / 0.0"
}
if touches.count >= 3 {
positionTouch3LBL.text = String(describing: touches[2].location(in: view))
} else {
positionTouch3LBL.text = "0.0 / 0.0"
}
if touches.count >= 4 {
positionTouch4LBL.text = String(describing: touches[3].location(in: view))
} else {
positionTouch4LBL.text = "0.0 / 0.0"
}
if touches.count >= 5 {
positionTouch5LBL.text = String(describing: touches[4].location(in: view))
} else {
positionTouch5LBL.text = "0.0 / 0.0"
}
【问题讨论】: