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

前端 未结 3 498
独厮守ぢ
独厮守ぢ 2021-01-18 05:35

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

3条回答
  •  独厮守ぢ
    2021-01-18 06:08

    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

    dropsFound += hitView
    

    use

    dropsFound.append(hitView!)
    

    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.

    var s: [String] = []
    // s += "hello"  // error: '[String]' is not identical to 'UInt8'
    s.append("hello")
    s
    

    There is an additional complexity if you are trying to append a tuple, and perhaps other types.

    // line below no longer works in Xcode 6 beta 5
    // and you will also get an error trying to append the tuple directly
    // which is probably a bug
    // possibleFlipsArray += (x, y)
    // possibleFlipsArray.append((x, y))
    let tempTuple = (x, y)
    possibleFlipsArray.append(tempTuple)
    

    This probably deserves its own question, though I think it is just another bug, so again I've posted it to Apple.

提交回复
热议问题