0

What I want to do is create a loop that allows pic and slide to have the same width and height constraints. Since I am constraining 0.25 to all constraints. I assume there is a way to do this without have to write all 4 lines of this code.

NSLayoutConstraint.activate([
  pic.heightAnchor.constraint(equalToConstant: 0.25),
  pic.widthAnchor.constraint(equalToConstant: 0.25),

  slide.heightAnchor.constraint(equalToConstant: 0.25),
  slide.widthAnchor.constraint(equalToConstant: 0.25),
])

1 Answer 1

0

You can do

[pic,slide].forEach {  
    $0.heightAnchor.constraint(equalToConstant: 0.25).isActive = true
    $0.widthAnchor.constraint(equalToConstant: 0.25).isActive = true
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.