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

IosSwiftCocoa TouchSwift2

Ios Problem Overview


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

Ios Solutions


Solution 1 - Ios

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]

Solution 2 - Ios

This are the differences between Swift 1.2 and 2:

// swift 1.2
view.autoresizingMask = .FlexibleWidth | .FlexibleTopMargin

// swift 2
view.autoresizingMask = [.FlexibleWidth, .FlexibleTopMargin]

Solution 3 - Ios

Try with xcode7-b6:

view.autoresizingMask = UIViewAutoresizing.FlexibleWidth.union(UIViewAutoresizing.FlexibleHeight)

Solution 4 - Ios

For Swift 3 Xcode 8 b1:

view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

Solution 5 - Ios

actual for swift 3.0.2:

view.autoresizingMask = [.layerWidthSizable, .layerHeightSizable]

Solution 6 - Ios

use this code swift 2 with Xcode 7.2

self.view.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin, .FlexibleTopMargin]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKhawarView Question on Stackoverflow
Solution 1 - IoskeithbhunterView Answer on Stackoverflow
Solution 2 - IosJorge CasariegoView Answer on Stackoverflow
Solution 3 - IosTai LeView Answer on Stackoverflow
Solution 4 - IosICL1901View Answer on Stackoverflow
Solution 5 - IosLiza PovalyaevaView Answer on Stackoverflow
Solution 6 - IosManinderjit SinghView Answer on Stackoverflow