Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find relevant edges for attributes

I get the following error:

Could not resolve symbolic constant for constraint, because: Could not find relevant edges for attributes: centerX and centerX.

Use a symbolic breakpoint at NSLayoutConstraintFailedToFindDefaultResolvedValueForSymbolicConstant to debug.

If I add a breakpoint at NSLayoutConstraintFailedToFindDefaultResolvedValueForSymbolicConstant it stops at this line:

[self.customNavigationBar.widthAnchor constraintEqualToAnchor:self.view.widthAnchor].active = YES;

This line is called within the viewDidLoad of the view controller. customNavigationBar is a UIView loaded from a nib which already have been added as subview to self.view.

If I try to print out the anchors I am using everything seems ok:

(lldb) po self.customNavigationBar.widthAnchor
<NSLayoutDimension:0x17446cc80 "UIView:0x10115c160.width">

(lldb) po self.view.widthAnchor
<NSLayoutDimension:0x170667080 "UIView:0x1012ae550.width">
like image 988
Nef10 Avatar asked Oct 19 '25 15:10

Nef10


1 Answers

This error comes from your choice of constructor for the NSLayoutConstraint.

You probably have something like this:

view.topAnchor.constraint(equalToSystemSpacingBelow: otherView.centerYAnchor, multiplier: 0.25).isActive = true

But you should construct it like this:

let constraint = NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: otherView, attribute: .centerY, multiplier: 0.25, constant: 1)

constraint.isActive = true
like image 183
Jon Vogel Avatar answered Oct 21 '25 05:10

Jon Vogel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!