Convert NSNotification.userInfo to Enum

Using NSNumber from NSNotification.userInfo[UIKeyboardAnimationCurveUserInfoKey]

In Objective C I would do the following

  • Change Label of UISwitch
  • How to identify different connected watches in iOS
  • Type 'Any' has no subscript members (firebase)
  • CLLocationManager and accuracy issues - any experiences?
  • new UIPDFPageRenderOperation error with iOS 9.3?
  • Setting up TeamCity to integrate to OSX Build Agent
  •  [UIView animateWithDuration:1.0
                          delay:0
                        options:(curveValue.intValue << 16)
    

    Swift will not allow me to do the same even though the bitshift operator is the same. I would like to get the enum raw value which is equivalent

    UIViewAnimationOptionCurveEaseInOut = 0 << 16,

    UIViewAnimationOptionCurveEaseIn = 1 << 16,

    UIViewAnimationOptionCurveEaseOut = 2 << 16,

    UIViewAnimationOptionCurveLinear = 3 << 16,

    update


    I am not sure if the below approach is correct , it seems to work

     var animationCurve : UIViewAnimationOptions = UIViewAnimationOptions.CurveEaseOut
     info[UIKeyboardAnimationCurveUserInfoKey].getValue(&animationCurve)
    
    
     UIView.animateWithDuration(durationValue.doubleValue,
            delay: 0,
            options: animationCurve,
            animations: {self.navigationController.toolbar.frame = myRect},
            completion: nil)
    

    4 Solutions Collect From Internet About “Convert NSNotification.userInfo to Enum”

    In Beta-5

    UIViewAnimationOptions.fromRaw(
        UInt(
            ( p.userInfo[ UIKeyboardAnimationCurveUserInfoKey ] as NSNumber ).unsignedIntValue << 16
        )
    )!
    

    You have to init a UIViewAnimationOptions with the rawValue like this:

    UIView.animateWithDuration(1.0,
    delay: 0,
    options: UIViewAnimationOptions.init(rawValue:UInt(curveValue.intValue << 16)),

    Is this what you need?

    UIViewAnimationCurve.fromRaw(Int(hereGoesYourStuff))
    
    let animationKey = userInfo[UIKeyboardAnimationCurveUserInfoKey] as UInt
    UIViewAnimationOptions(rawValue: animationKey)