2
我使用的是從https://github.com/brightec/CustomCollectionViewLayout CustomCollectionViewLayout。轉換Swift2 - > Swift3:任何錯誤
從Swift2轉換到Swift3後,出現了兩個關於Any的錯誤。
ERROR1:
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
return self.itemAttributes[indexPath.section][indexPath.row] as! UICollectionViewLayoutAttributes
}
消息錯誤:
CustomCollectionViewLayout.swift:115:54: Type 'Any' has no subscript members
錯誤2:
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var attributes = [UICollectionViewLayoutAttributes]()
if self.itemAttributes != nil {
for section in self.itemAttributes {
let filteredArray = (section as AnyObject).filtered(
using: NSPredicate(block: { (evaluatedObject, bindings) -> Bool in
return rect.intersects(evaluatedObject.frame)
})
) as! [UICollectionViewLayoutAttributes]
attributes.append(contentsOf: filteredArray)
}
}
return attributes
}
消息錯誤:
Value of type 'Any?' has no member 'frame'
任何想法如何解決Any/AnyObject的問題?
我也面臨着同樣的問題 –