Binary operator '|' cannot be applied to two UIViewAutoresizing operands

Khawar picture Khawar · Jun 16, 2015 · Viewed 46.2k times · Source

Getting this error in Swift 2.0.

Binary operator '|' cannot be applied to two UIViewAutoresizing operands

Here is the code:

let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 568))
addSubview(view)
view.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight

Any idea what can be the problem? enter image description here

Answer

keithbhunter picture keithbhunter · Jun 16, 2015

The OptionSetType got an updated syntax for Swift 2.x and another update for Swift 3.x

Swift 3.x

view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

Swift 2.x

view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]