chiahsien/CHTCollectionViewWaterfallLayout

Crash in shortestColumnIndexInSection

SureshSc opened this issue · 1 comments

Hi I try to use the example app with Swift3 and i face the crash issue in

func shortestColumnIndexInSection (_ section: NSInteger) -> NSInteger {
    var index = 0
    var shorestHeight = MAXFLOAT
    (self.columnHeights[section] as AnyObject).enumerateObjects { (obj: Any, idx: NSInteger, pointer: UnsafeMutablePointer<ObjCBool>) in
        let height = obj as! Float
        if (height<shorestHeight){
            shorestHeight = height
            index = idx
        }
    }
    return index
}

App getting crash in this line.
let height = obj as! Float
When i try to check for that nil in the above function,(i.e)
let height = obj as? Float if (height != nil && height<shorestHeight){ shorestHeight = height! index = idx }
My collectionview layout is in single coloum (i.e instead of two column it comes in single column)

Crash
screen shot 2017-05-11 at 12 28 41 pm

Not knowing what the issue is, plus I haven't used the module yet the code from above could be swiftified to (almost never ever use force-cast or IUO's):

// This is far more safe than the original code
if let height = obj as? Float, height < shortestHeight {
     shortestHeight = height
     index = idx
}

Btw. fix the typo in shorestHeight to shortestHeight.