简体   繁体   English

NSLayoutContraint中的UIView在swift中不符合AnyObject

[英]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. 在复制粘贴并尝试将一些Objective-C代码修改为我的swift项目后,我遇到了同样的错误。 I realized that I had left relatedBy as 0 instead of NSLayoutRelation.Equal. 我意识到我已将relatedBy保留为0而不是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. 很奇怪编译器会在第一个参数显示错误时显示错误,因为它确实是relatedBy的一个问题。 Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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