Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView in NSLayoutContraint does not conform to AnyObject in swift

Tags:

ios

swift

I have found this question and answer here however I get the error

Type 'UIView!' does not conform to protocol 'AnyObject'

for

...
@IBOutlet var mainView: UIView!
@IBOutlet weak var contentView: UIView!
...
NSLayoutConstraint(item: self.contentView, ...`

Is there somthing happening with dereferencing the view object?

like image 208
Mika571 Avatar asked Dec 11 '22 02:12

Mika571


1 Answers

I was getting the same error after copy-pasting and trying to modify some Objective-C code into my swift project. I realized that I had left relatedBy as 0 instead of NSLayoutRelation.Equal. After fixing that the error went away. Weird that the compiler would show the error on the first parameter when it was really an issue with the relatedBy. Hope it helps.

like image 194
rdmurphy Avatar answered May 14 '23 10:05

rdmurphy