CFDictionary does not cast to Dictionary in Swift 2.1

Originator:ilyapuchka
Number:rdar://23430664 Date Originated:6.11.15
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1(7B91b)
Classification:Other bugs Reproducible:
 
In Swift 1.x this works and `properties` are casted to `[NSObject: AnyObject]`:
    
    func imageOwnerWithURL(url: NSURL) -> ZMImageOwner! {
        if let source = CGImageSourceCreateWithURL(url, nil),
            properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [NSObject: AnyObject],
            ...
    }
    
    In Swift 2 'as? [NSObject: AnyObject]' does not work anymore and returns nil, the same with 'as? Dictionary' or 'as? NSDictionary' 
But this works:
    
    func imageOwnerWithURL(url: NSURL) -> ZMImageOwner! {
      if let source = CGImageSourceCreateWithURL(url, nil),
          properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as Dictionary?,
          ...
    }

Expected Results:
If 'CFDictionary? as Dictionary?' works then 'CFDictionary? as? Dictionary' should work the same way

Actual Results:
'CFDictionary? as? Dictionary' returns nil
'CFDictionary? as Dictionary?' returns casted dictionary

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!