I was using += to an a UIView to an array and that no longer seems to work. The line
dropsFound += hitView
Gives an error '[(UIView)]' is not identical to 'UInt8'
Here is part of the method. Note that as of Xcode 6 beta 5, hitTest now returns an optional, so it was necessary to say
hitView?.superview
instead of
hitView.superview
in the 'if' statement.
func removeCompletedRows() -> Bool {
println(__FUNCTION__)
var dropsToRemove = [UIView]()
for var y = gameView.bounds.size.height - DROP_SIZE.height / 2; y > 0; y -= DROP_SIZE.height {
var rowIsComplete = true
var dropsFound = [UIView]()
for var x = DROP_SIZE.width / 2; x <= gameView.bounds.size.width - DROP_SIZE.width / 2; x += DROP_SIZE.width {
let hitView = gameView.hitTest(CGPointMake(x, y), withEvent: nil)
if hitView?.superview === gameView {
dropsFound += hitView
} else {
rowIsComplete = false
break
}
}
... remainder of method omitted
The solution appears to be that you need to use the append method for the array rather than +=. I don't know the reason for this, so another answer might be more appropriate.
Instead of
use
Again, note that the UIView returned from hitTest is an optional as of Xcode 6 beta 5.
I verified that this is a general problem with arrays with the following playground sample. A bug report has been posted to Apple.
There is an additional complexity if you are trying to append a tuple, and perhaps other types.
This probably deserves its own question, though I think it is just another bug, so again I've posted it to Apple.
That changed in the last release. From the beta 5 release notes:
So if the left side of
+=
is an array, the right now must be as well.so:
Or if you really wanted to use
+=
you could probably do:But that would be a little silly. Use
append
like the error message suggests.adding object in array dropsFound += hitView,in this way, is removed in last release. You can add element in array by using this syntax dropsFound += [hitView] or dropsFound.append(hitView)