배열의 두 개 이상의 CGPoint가 같은 좌표를 가지고 있는지 확인하는 Swift extension
을 쓰고 있습니다. 이 코드를 가지고 배열의 모든 점을 검사 할 수 있습니다. 하지만 몇 가지 요소를 확인하는 방법 (전부가 아닌)은 무엇입니까? 두 개 (또는 그 이상)의 붉은 CGPoints들이 그린 사람으로 설정되어 있어야합니다 동일한 좌표가있는 경우여러 배열의 요소가 같은 좌표를 가지고 있는지 확인하십시오.
여기
import Foundation
extension Array where Element : Equatable {
func equalCoordinates() -> Bool {
if let firstElement = first {
return dropFirst().contains { $0 == firstElement }
}
return true
}
}
... 확장입니다.
... 그리고 equalCoordinates()
방법 사용의 ViewController의 코드 (즉, 데이터의 크기에 따라 개선 될 수있다) 효율을 주어 전혀 우려
func drawn() {
let colorArray = array.map { $0.pointCoord()[0] }
for dot in array {
for cPoint in dot.pointCoord() {
if colorArray.equalCoordinates() {
let altColor = dot.alternativePointColour()
draw(cPoint, color: altColor)
} else {
let color = dot.pointColour()
draw(cPoint, color: color)
}
}
}
}
...........
Swift.print(colorArray.equalCoordinates())
...........
여러 무엇을 의미합니까? 그들 범위? 그들 색인의 집합? 한번에 한? – ColGraff
@ColGraff 범위 내의 둘 이상의 CGPoints입니다. 인덱스가있는 경우 가능합니다. – andy
그래서 동일한 원소의 인덱스를 반환하고 싶습니까? – ColGraff