gpt4 book ai didi

uiview - '[(UIView) ]' is not identical to ' UInt8' 在 Xcode 6 beta 5 中使用 += 时。改用 append 方法?

转载 作者:搜寻专家 更新时间:2023-10-30 21:48:59 25 4
gpt4 key购买 nike

我使用 += 将 UIView 用于数组,但似乎不再有效。线路

dropsFound += hitView

给出错误 '[(UIView)]' is not identical to 'UInt8'

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

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
}
}

...省略方法的其余部分

最佳答案

在上一个版本中发生了变化。来自 Beta 5 发行说明:

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

所以如果 += 的左边是一个数组,那么右边 now 也一定是数组。

所以:

dropsFound.append(hitView)

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

dropsFound += [hitView]

但这有点傻。按照错误消息的建议使用 append

关于uiview - '[(UIView) ]' is not identical to ' UInt8' 在 Xcode 6 beta 5 中使用 += 时。改用 append 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25128122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com