0

I'm going to init an array with 6 UIImageViews in this way:

var imageViews = [UIImageView](repeating: UIImageView(), count: 6)

But I found that every element in it has the same address. If I change one imageView I'll change all of them.

I don't know how it works and what should I do to separate them?

1

1 Answer 1

0

That's just how it works.

If you check the documentation, it states:

Creates a new collection containing the specified number of a single, repeated value.

If you want separate values, create them explicity

var imageViews = [UIImageView(), UIImageView(), UIImageView(), ...]

Or use a loop. But always check the docs if something unexpected happens because you will either have found a bug in the SDK, or an error in your own assumptions.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.