James D. Schwartz James D. Schwartz - 2 years ago 108
Swift Question

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

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download