此代码用于 swift 2.3 及更早版本。但是当我在 Swift 3 中更新它时,应用程序崩溃了。
这是 swift 2.3 中的代码
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]?
{
var layoutAttributes = [UICollectionViewLayoutAttributes]()
layoutInfo?.enumerateKeysAndObjectsUsingBlock({ (object: AnyObject, elementInfo: AnyObject, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
let infoDic = elementInfo as! NSDictionary as NSDictionary!
infoDic.enumerateKeysAndObjectsUsingBlock( { (object: AnyObject!, attributes: AnyObject!, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
let attr = attributes as! UICollectionViewLayoutAttributes
if (CGRectIntersectsRect(rect, attributes.frame))
{
layoutAttributes.append(attr)
}
})
})
return layoutAttributes
}
这是 Swift 3 的更新版本
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var layoutAttributes = [UICollectionViewLayoutAttributes]()
layoutInfo?.enumerateKeysAndObjects({ (object: AnyObject, elementInfo: AnyObject, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
let infoDic = elementInfo as! NSDictionary as NSDictionary!
infoDic?.enumerateKeysAndObjects( { (object: AnyObject!, attributes: AnyObject!, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
let attr = attributes as! UICollectionViewLayoutAttributes
if (rect.intersects(attributes.frame))
{
layoutAttributes.append(attr)
}
} as! (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Void)
} as! (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Void)
return layoutAttributes
}
我在 } 时遇到了这个崩溃!(Any, Any, UnsafeMutablePointer) -> Void) EXC_BREAKPOINT
任何人都可以帮助我吗?
这是我从这个人那里得到的项目。 https://github.com/CoderXpert/EPGGrid