Этот код использовался для работы в swift 2.3 и ранее. Но когда я обновил его в Swift 3, приложение рушится.layoutAttributesForElementsInRect Swift 3 (UICollectionView)
Это код в быстром 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
}
это обновленная версия Свифт 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
}
Я получаю эту аварию в} как! (Любой, Любой, UnsafeMutablePointer) -> Пустота) EXC_BREAKPOINT
Кто-нибудь может мне помочь?
Это проект, который я взял у этого парня. https://github.com/CoderXpert/EPGGrid
Да, это словари .. есть способ, которым я могу заполнить кеш с моим layoutInfo и infoDic? – jboisjoli