James D. Schwartz James D. Schwartz - 7 months ago 22
Swift Question

"Cannot assign to property: "any" is immutable" error

tiledViewsStack
contains UIImageViews. I'm trying to give each UIImageView in the array a new center coordinate. Not sure why I'm getting this error for the last line in the for loop... enter image description here

var tiledViewsStack = [AnyObject]()

var randLocInt = Int()
var randLoc = CGPoint()

for var any in tiledViewsStack
{
randLocInt = Int((arc4random()*10) % 9) // 0, --- 8
randLoc = allCenters[randLocInt].CGPointValue()
any.center = randLoc
}

Answer

Needed to make tiledViewsStack a stack of UIImages, not AnyObjects. Changed var tiledViewsStack = [AnyObject]() to var tiledViewsStack = [UIImageView]().

Comments