UIView in NSLayoutContraint does not match AnyObject in swift

I found this question and answer here , however I get an 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 something that happens to dereferencing an object of a view?

+4
source share
1 answer

I was getting the same error after copying and trying to modify Objective-C code into my quick project. I realized that I left the associated By as 0, not NSLayoutRelation.Equal. After fixing the error, the error disappeared. It is strange that the compiler will show an error on the first parameter when this is really a problem with relatedBy. Hope this helps.

+13
source

All Articles