Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in shortestColumnIndexInSection #172

Open
SureshSc opened this issue May 11, 2017 · 1 comment
Open

Crash in shortestColumnIndexInSection #172

SureshSc opened this issue May 11, 2017 · 1 comment

Comments

@SureshSc
Copy link

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

@DevAndArtist
Copy link

DevAndArtist commented May 15, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants