ipnicholson
ipnicholson

Reputation: 57

Swift: Most efficient way to place an entire array?

I'm placing all 4 items from an array graphics, then moving three of them.

Besides a for loop, is there a shorter way to place the entire array graphics at the same position? i.e. How do I place an entire array at a single point?

// Position a graphic in each quadrant.
for i in 0 ... 3 {
    scene.place(graphics[i], at: Point(x: x, y: y))
}
graphics[1].move(to: Point(x: x, y: -y), duration: 2)
graphics[2].move(to: Point(x: -x, y: -y), duration: 2)
graphics[3].move(to: Point(x: -x, y: y), duration: 2)

Upvotes: 2

Views: 59

Answers (1)

Leif
Leif

Reputation: 293

Try using graphics.forEach{ scene.place($0, at: Point(x: x, y: y)) }

Upvotes: 1

Related Questions