在 Xcode 6 beta 5 中使用 += 时,'[(UIView)]' 与 'UInt8' 不同.使用 append 方法代替? [英] '[(UIView)]' is not identical to 'UInt8' when using += in Xcode 6 beta 5. Use append method instead?

查看:20
本文介绍了在 Xcode 6 beta 5 中使用 += 时,'[(UIView)]' 与 'UInt8' 不同.使用 append 方法代替?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 += 到一个 UIView 到一个数组,但似乎不再起作用.线

I was using += to an a UIView to an array and that no longer seems to work. The line

dropsFound += hitView

给出错误[(UIView)]"与UInt8"不同

Gives an error '[(UIView)]' is not identical to 'UInt8'

这是方法的一部分.请注意,从 Xcode 6 beta 5 开始,hitTest 现在返回一个可选的,所以有必要说

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

代替

hitView.superview

在if"语句中.

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

推荐答案

在上一个版本中有所改变.来自 Beta 5 发行说明:

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

数组上的 += 运算符只连接数组,它不附加元素.这解决了使用 AnyAnyObject 和相关类型时的歧义.

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.

所以:

dropsFound.append(hitView)

或者如果你真的想使用 += 你可以这样做:

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

dropsFound += [hitView]

但那会有点傻.像错误消息建议的那样使用 append.

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

这篇关于在 Xcode 6 beta 5 中使用 += 时,'[(UIView)]' 与 'UInt8' 不同.使用 append 方法代替?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆