Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'[(UIView)]' is not identical to 'UInt8' when using += in Xcode 6 beta 5. Use append method instead?

Tags:

swift

uiview

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

like image 820
kasplat Avatar asked Aug 04 '14 21:08

kasplat


1 Answers

That changed in the last release. From the beta 5 release notes:

The += operator on arrays only concatenates arrays, it does not append an element. This resolves ambiguity working with Any, AnyObject and related types.

So if the left side of += is an array, the right now must be as well.

so:

dropsFound.append(hitView)

Or if you really wanted to use += you could probably do:

dropsFound += [hitView]

But that would be a little silly. Use append like the error message suggests.

like image 69
Alex Wayne Avatar answered Nov 02 '22 14:11

Alex Wayne