Binary operator ‘|’ cannot be applied to two ‘UIViewAutoresizing’ operands

来源:互联网 发布:电脑网络共享怎么取消 编辑:程序博客网 时间:2024/05/29 18:29

OC的写法:

_tableView.autoresizingMask= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight

swift的写法:

_tableView.autoresizingMask= .flexibleHeight | .flexibleWidth


如果是把OC的代码直接翻译成swift的话,直接按照上面的写法来写的话,会报错的,报错如下:

Binary operator ‘|’ cannot be applied to two ‘UIViewAutoresizing’ operands

错误原因是:

swift 2.x 和swift 3 对于OptionSetType这个类型进行了优化升级修改。


解决方案是:

_tableView.autoresizingMask = [.flexibleHeight,.flexibleWidth]



0 0
原创粉丝点击