xcode - '+=' cannot be applied to two [AnyObject] operands -


i have following code try , create array of constraints add view:

let views = ["button": button] let metrics = ["margin": 16]  var constraints: [anyobject] = [] constraints += nslayoutconstraint.constraintswithvisualformat("|-margin-[button]-margin-|", options: 0, metrics: metrics, views: views) 

from understand swift arrays, should able '+=' them join two, error:

"binary operator '+=' cannot applied 2 [anyobject] operands"

what's wrong code?

it's not because of operator. it's because passing in int supposed pass nslayoutformatoptions enum type.

if pass in 1 of nslayoutformatoptions enum options parameter, error go away:

constraints += nslayoutconstraint.constraintswithvisualformat("|-margin-[button]-margin-|", options: .alignallleft, metrics: metrics, views: views) 

or initialize nslayoutformatoptions int value want use, this:

nslayoutformatoptions(rawvalue: 0) 

0 have worked in objective-c, need use actual enum value in swift. swift errors still misleading in many cases, one.

hope helps.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -