gpt4 book ai didi

ios - 二元运算符 '+=' 不能应用于 Swift 3 中 UICollectionViewLayoutAttributes 类型的操作数

转载 作者:行者123 更新时间:2023-11-28 21:07:38 27 4
gpt4 key购买 nike

我们有以下代码在 Swift 3 中不再工作,但在以前的 Swift 版本中工作。在代码行 array += [attributes] 中,我们收到错误“Binary Operator '+=' cannot be applied to operands of type UICollectionViewLayoutAttributes and UICollectionViewLayoutAttributes?”。任何建议:这是代码:

override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var array: [UICollectionViewLayoutAttributes] = []
for i in 0 ... max(0, numberOfItems - 1) {
var indexPath = IndexPath(item: i, section: 0)
var attributes = layoutAttributesForItem(at: indexPath)
if attributes != nil {
array += [attributes]
}
}
return array
}

最佳答案

尝试使用

array.append(attributes)

代替

array += [attributes]

关于ios - 二元运算符 '+=' 不能应用于 Swift 3 中 UICollectionViewLayoutAttributes 类型的操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44917379/

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