你好,我不是Swift开发人员,我只是从GitHub克隆存储库,在我更新Xcode版本和Swift之前,它一直在工作。我在这里寻求帮助,这是代码,我收到的构建错误说
编译器无法在合理的时间内对此表达式进行类型检查;尝试将表达式分解为不同的子表达式
是位于几个地方,我我只是不知道如何解决它.我在网上看到的问题是太难表达的代码和许多操作在一次.代码需要简化,但idk如何做到这一点在swift.任何帮助将是受欢迎的存储库是死的,所有者没有在线一年.
返回表达式|representedElements + cells.flatMap { group -> [UICollectionViewLayoutAttributes] in
出错!x编译器无法在合理的时间内对该表达式进行类型检查;尝试将表达式分解为不同的子表达式
return representedElements + cells.flatMap { group -> [UICollectionViewLayoutAttributes] in
guard let section = group.first?.indexPath.section else {
return group
}
let evaluatedSectionInset = evaluatedSectionInsetForSection(at: section)
let evaluatedMinimumInteritemSpacing = evaluatedMinimumInteritemSpacingForSection(at: section)
var origin = (collectionView.bounds.width + evaluatedSectionInset.left - evaluatedSectionInset.right - group.reduce(0, { $0 + $1.frame.size.width }) - CGFloat(group.count - 1) * evaluatedMinimumInteritemSpacing) / 2
// we reposition each element of a group
return group.map {
$0.frame.origin.x = origin
origin += $0.frame.size.width + evaluatedMinimumInteritemSpacing
return $0
}
}
} else {
for layoutAttributes in layoutAttributesForElements {
guard layoutAttributes.representedElementKind == nil else {
representedElements.append(layoutAttributes)
continue
}
// copying is required to avoid "UICollectionViewFlowLayout cache mismatched frame"
let currentItemAttributes = layoutAttributes.copy() as! UICollectionViewLayoutAttributes
// if the current frame, once stretched to the full column doesn't intersect the previous frame then they are on different columns
if previousFrame != nil && !currentItemAttributes.frame.intersects(CGRect(x: previousFrame!.origin.x, y: -.greatestFiniteMagnitude, width: previousFrame!.size.width, height: .infinity)) {
cells.append([])
}
cells[cells.endIndex - 1].append(currentItemAttributes)
previousFrame = currentItemAttributes.frame
}
// we reposition all elements
return representedElements + cells.flatMap { group -> [UICollectionViewLayoutAttributes] in
guard let section = group.first?.indexPath.section else {
return group
}
let evaluatedSectionInset = evaluatedSectionInsetForSection(at: section)
let evaluatedMinimumInteritemSpacing = evaluatedMinimumInteritemSpacingForSection(at: section)
var origin = (collectionView.bounds.height + evaluatedSectionInset.top - evaluatedSectionInset.bottom - group.reduce(0, { $0 + $1.frame.size.height }) - CGFloat(group.count - 1) * evaluatedMinimumInteritemSpacing) / 2
// we reposition each element of a group
return group.map {
$0.frame.origin.y = origin
origin += $0.frame.size.height + evaluatedMinimumInteritemSpacing
return $0
}
}
}
1条答案
按热度按时间nhjlsmyf1#
在我看来,编译器无法找出表达式
representedElements + cells.flatMap { <closure> }
的结果类型。尝试在返回值上添加显式类型:(It很难知道发生了什么,因为我们不知道变量
representedElements
、group
或cells
的类型。我不得不猜测代码应该返回的数组的正确类型。)