简体   繁体   中英

UIView in NSLayoutContraint does not conform to AnyObject in 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM