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

Unable to bridge NSNumber to Float #38

Closed
turk-jk opened this issue Apr 4, 2018 · 3 comments
Closed

Unable to bridge NSNumber to Float #38

turk-jk opened this issue Apr 4, 2018 · 3 comments

Comments

@turk-jk
Copy link

turk-jk commented Apr 4, 2018

I have know idea what I'm doing wrong but it's crashing since swift 4.1
` }

    let frameDelays: [Float] = frameProperties.map() {
        var delayObject: AnyObject = unsafeBitCast(CFDictionaryGetValue($0, Unmanaged.passUnretained(kCGImagePropertyGIFUnclampedDelayTime).toOpaque()), to: AnyObject.self)
        if (delayObject.floatValue == 0.0){
            delayObject = unsafeBitCast(CFDictionaryGetValue($0, Unmanaged.passUnretained(kCGImagePropertyGIFDelayTime).toOpaque()), to: AnyObject.self)
        }
        return delayObject as! Float   // <-- error occurs here
    }
    return frameDelays
}`
@sarrathy
Copy link

sarrathy commented Apr 13, 2018

Same issue for me too
For now i hard coded it .
if let probability = delayObject as? Float{
return probability
}
return 0.1

@BeckWang0912
Copy link

I suggest this
if let n = delayObject as? NSNumber { return n.floatValue }

@proxpero
Copy link
Contributor

I fixed this with
return delayObject.floatValue as Float

ie. get the scalar float value out of the NSNumber object before trying to bridge. It should always succeed.

proxpero added a commit to proxpero/AImage that referenced this issue May 17, 2018
Yuya-Tominaga-VIT pushed a commit to GroupVantageApps/AImage that referenced this issue Apr 9, 2020
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

5 participants