Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with addConstraints()? #6

Open
YoonjaeYoo opened this issue Jan 16, 2017 · 1 comment
Open

How to use with addConstraints()? #6

YoonjaeYoo opened this issue Jan 16, 2017 · 1 comment

Comments

@YoonjaeYoo
Copy link

Swiftstraints helps me a lot because it reduces a lot of codes and I love it.
One thing I'm curious is, if there's another way of adding constraints instead of set isActive on each constraint.

As is:

        let iconView = UIImageView(image: UIImage(named: "Icon"))
        view.addSubview(iconView)
        iconView.translatesAutoresizingMaskIntoConstraints = false
        (iconView.widthAnchor == 120.0).isActive = true
        (iconView.heightAnchor == 120.0).isActive = true
        (iconView.centerXAnchor == view.centerXAnchor).isActive = true
        (iconView.centerYAnchor == view.centerYAnchor - Spacing.large).isActive = true

To be:

        let iconView = UIImageView(image: UIImage(named: "Icon"))
        view.addSubview(iconView)
        iconView.translatesAutoresizingMaskIntoConstraints = false
        iconView.addConstraints([
                (iconView.widthAnchor == 120.0),
                (iconView.heightAnchor == 120.0),
                (iconView.centerXAnchor == view.centerXAnchor),
                (iconView.centerYAnchor == view.centerYAnchor - Spacing.large)
        ])

But the To be code isn't compiled, it says:
Error:(17, 41) binary operator '==' cannot be applied to two 'NSLayoutXAxisAnchor' operands.

Is there any workaround?
Thank you.

@RomanPodymov
Copy link
Contributor

Hello @web3-guru
The issue that you described is not reproducing on my side. Are you using the latest Swiftstraints version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants